Improve EmoTracker.Core performance, thread safety, and API flexibility#65
Open
Improve EmoTracker.Core performance, thread safety, and API flexibility#65
Conversation
Performance: - Cache type-tag lookups in JsonTypeTagsAttribute to avoid lock contention and full type scan on every deserialization call; rename CreateIntanceForTypeTag to CreateInstanceForTypeTag (typo fix) - Fix ObservableCollectionExtensions.Sort O(n^2) by avoiding repeated IndexOf - Use object lock instead of string literal in TypeRegistry/TypedObjectRegistry to eliminate cross-type deadlock risk from string interning - Fix TypeRegistry.GetTypes() crash when assembly has missing dependencies (add try/catch, matching TypedObjectRegistry's defensive pattern) - Fix TypedObjectRegistry null deref when ReflectionTypeLoadException has null LoaderExceptions property API additions: - Add Invoke<T>(Func<T>), Invoke(Func<Task>), BeginInvoke(Func<Task>) to DispatchService backend, eliminating TaskCompletionSource workarounds - Add exception-aware Debug/Info/Warn/Error overloads to LogService backend for structured logging support - Add CancellationToken parameter and Cancel() method to all collection synchronizers (ObservableCollectionSynchronizer, ObservableCollectionAggregatorSynchronizer, ObservableCollectionUniqueSetAggregrator and all derived classes) Thread safety: - Use Interlocked.Exchange for mActiveBackend in Log and Dispatch service backends to prevent TOCTOU race when swapping backends Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
JsonTypeTagsAttributeto avoid lock contention and full type scan on every deserialization call; renameCreateIntanceForTypeTag→CreateInstanceForTypeTag(typo fix)ObservableCollectionExtensions.SortO(n^2) by avoiding repeatedIndexOfobjectlock instead of string literal"Registry"inTypeRegistry/TypedObjectRegistryto eliminate cross-type deadlock risk from string interningTypedObjectRegistrynull deref whenReflectionTypeLoadException.LoaderExceptionsis nullTypeRegistry.GetTypes()to prevent crash on assemblies with missing dependenciesInvoke<T>(Func<T>),Invoke(Func<Task>),BeginInvoke(Func<Task>)to dispatch service backend, eliminatingTaskCompletionSourceworkaroundsDebug/Info/Warn/Error(Exception, ...)overloads to log service backend for structured logging supportCancellationTokenparameter andCancel()method to all collection synchronizers and their derived classesInterlocked.ExchangeformActiveBackendin Log/Dispatch service backends to prevent TOCTOU race during backend swapsTest plan
dotnet build EmoTracker/EmoTracker.csproj— passes cleanJsonTypeTagsAttribute.CreateInstanceForTypeTagworks with cached dictionary for multiple type argumentsObservableCollectionSynchronizerMTandBufferedObservableCollectionSynchronizerMTCancel()overrides workInvoke<T>,Invoke(Func<Task>),BeginInvoke(Func<Task>)) work correctly in the UILog.Error(ex, ...)) forwards exception to Serilog correctlyTypeRegistryandTypedObjectRegistrydon't crash when assemblies have missing dependencies🤖 Generated with Claude Code