Skip to content

Commit 1dd3f30

Browse files
thomhurstclaude
andauthored
perf: Replace exclusive lock with ReaderWriterLockSlim in ModuleScheduler (#1469)
* chore: Add .worktrees/ to .gitignore for parallel development 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * perf: Replace exclusive lock with ReaderWriterLockSlim in ModuleScheduler Refactor ModuleScheduler locking strategy to reduce contention in the hot execution path. The previous implementation held an exclusive lock during read-only operations like querying module states and statistics. Changes: - Replace `object _stateLock` with `ReaderWriterLockSlim` - Use read locks for query operations (GetStatistics, GetPendingModules, GetExecutingModules, ShouldExitScheduler snapshot creation) - Use write locks for state mutations (MarkModuleStarted, MarkModuleCompleted, AddModule, FindReadyModules, CancelPendingModules) - Move LINQ processing and logging operations outside of locks where possible - Add proper disposal of the ReaderWriterLockSlim This allows concurrent reads while maintaining exclusive access for writes, improving performance in scenarios with many parallel module queries. Fixes #1458 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix: Address code review feedback - race conditions and logging bug 1. ShouldExitScheduler: Keep read lock held while evaluating exit conditions to prevent state changes between snapshot and decision. The isDeadlocked check is now captured under the read lock before upgrading to write lock. 2. CancelPendingModules: Fix copy-paste bug where logging statement was hardcoded to log ModuleExecutionState.Completed instead of the original state before modification. Now captures original state before modifying and logs that value. 3. AddModule: Move dependency resolution inside the write lock to prevent race conditions where _moduleStates could change between resolution and processing. Logging of unregistered dependencies is done outside the lock to avoid holding the lock during I/O. 🤖 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 f01ebb4 commit 1dd3f30

1 file changed

Lines changed: 184 additions & 64 deletions

File tree

0 commit comments

Comments
 (0)