Commit c4a95b8
perf: Replace Dictionary+lock with ConcurrentDictionary in ModuleResultRegistry (#1726)
* perf: Replace Dictionary+lock with ConcurrentDictionary in ModuleResultRegistry (#1540)
Use ConcurrentDictionary for lock-free reads and thread-safe writes,
reducing lock contention during parallel module execution.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Use GetOrAdd in all RegisterResult/SetException methods to prevent race condition
Ensures TCS is created atomically when registering results/exceptions,
preventing race conditions where TryGetValue might miss a not-yet-registered
module entry.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Reorder operations to prevent race condition in GetCompletionTask
Create TCS before storing result to ensure GetCompletionTask never
returns null when a result already exists. This prevents a race where:
1. Thread A stores result
2. Thread B calls GetCompletionTask, gets null (TCS doesn't exist)
3. Thread A creates TCS
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Add memory barrier to ensure result visibility before task completion
Adds Thread.MemoryBarrier() between writing to _results and calling
TrySetResult. This ensures that threads waking up from task completion
will see the _results write, preventing a potential memory visibility
race condition on weak memory model architectures.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: Simplify memory ordering and fix GetCompletionTask consistency
- Remove explicit Thread.MemoryBarrier() - TrySetResult already provides
release semantics ensuring _results write is visible to awaiters
- Change GetCompletionTask to use GetOrAdd for consistency with SetException
(both now create TCS on-demand)
- Update interface: GetCompletionTask now returns Task instead of Task?
since it always returns a valid task
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* fix: Preserve original behavioral semantics for SetException and GetCompletionTask
Revert behavioral changes to maintain backward compatibility:
- SetException: Only sets exception if module was previously registered
(does nothing for unregistered modules, matching original behavior)
- GetCompletionTask: Returns null for unregistered modules
(matching original behavior)
RegisterResult methods still use GetOrAdd since registering a result
implies the module should be tracked.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>1 parent 0e51348 commit c4a95b8
1 file changed
Lines changed: 27 additions & 51 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
68 | | - | |
69 | | - | |
| 69 | + | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
| 74 | + | |
80 | 75 | | |
81 | 76 | | |
82 | 77 | | |
83 | 78 | | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
93 | 84 | | |
94 | 85 | | |
95 | 86 | | |
96 | 87 | | |
97 | | - | |
| 88 | + | |
98 | 89 | | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 90 | + | |
105 | 91 | | |
| 92 | + | |
| 93 | + | |
106 | 94 | | |
107 | 95 | | |
108 | 96 | | |
109 | 97 | | |
110 | | - | |
| 98 | + | |
111 | 99 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
| 100 | + | |
118 | 101 | | |
| 102 | + | |
| 103 | + | |
119 | 104 | | |
120 | 105 | | |
121 | 106 | | |
122 | 107 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
| 108 | + | |
127 | 109 | | |
128 | 110 | | |
129 | 111 | | |
130 | 112 | | |
131 | | - | |
| 113 | + | |
| 114 | + | |
132 | 115 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 116 | + | |
137 | 117 | | |
138 | 118 | | |
139 | 119 | | |
140 | 120 | | |
141 | 121 | | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
151 | 127 | | |
152 | 128 | | |
0 commit comments