-
-
Notifications
You must be signed in to change notification settings - Fork 108
perf: make methods synchronous and defer List creation
#4366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rrentDictionary`
SummaryThis PR optimizes EventReceiverOrchestrator and HookExecutor by making methods synchronous when possible, changing return type to IReadOnlyList, and replacing ThreadSafeDictionary with ConcurrentDictionary. Critical IssuesThreadSafeDictionary to ConcurrentDictionary Change Requires Careful ReviewThe change from ThreadSafeDictionary to ConcurrentDictionary for _assemblyTestCounts and _classTestCounts is potentially risky. ThreadSafeDictionary uses Lazy with LazyThreadSafetyMode.ExecutionAndPublication to guarantee the factory function executes exactly once per key. ConcurrentDictionary.GetOrAdd does NOT guarantee single factory execution - multiple Counter instances can be created during races. This might be safe because InitializeTestCounts pre-populates all counters before test execution, so GetOrAdd calls during test execution should always find existing counters. However, this safety depends on initialization order guarantees that are not obvious from the code. If refactoring breaks this ordering, race conditions could occur where multiple threads create separate Counter instances for the same key, causing incorrect test counts and Last events firing at wrong times. Recommendation: This change is acceptable IF initialization ordering is guaranteed AND a code comment is added explaining why ConcurrentDictionary is safe despite Counter being a reference type. Suggestions
VerdictREQUEST CHANGES - Add a code comment explaining why ConcurrentDictionary is safe here, or revert to ThreadSafeDictionary if initialization ordering is not guaranteed. The rest of the performance optimizations are excellent. |
I don't see how this is an issue, the same Should I remove this change and bundle it in a different |
ValueTask<IReadOnlyList<Exception>>and return an empty array when possibleEventReceiverOrchestratormethods synchronous when possible to eliminate state machine creationThreadSafeDictionarywithConcurrentDictionaryas thevalueFactorydoesn't need the run once guaranteeAs usual I don't think the non-generic
ValueTaskare usefulBefore
After