Optimize pack load performance (~7.8s to <1s) - #38
Merged
Conversation
…nd building Pack load for Codetracker Map Tracker was taking ~7.8s. Three optimizations: 1. Dictionary index for GetPersistableLocationReference/ItemReference: Replace O(n) List.IndexOf with O(1) dictionary lookup. LocationDatabase and ItemDatabase now maintain a Dictionary<T, int> populated on insert. Saves ~2.9s from 583 location lookups during voice command building. 2. Defer BuildCommandMap to background thread: Voice recognition command map building (~5s) now runs on Task.Run with snapshots of item/location data. Atomic swap under lock ensures thread safety. Cancellable on pack switch. Completely removes voice recognition from the critical path. 3. Code-to-provider index in ItemDatabase: New BuildCodeIndex() creates a Dictionary<string, List<ITrackableItem>> mapping codes to their providers. LuaItems (dynamic Lua callbacks) fall back to brute-force iteration. All item types implement GetAllProvidedCodes() to expose their static code sets. ProviderCountForCode and related methods use the index when available, avoiding iteration over all items for each code query. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… exception handling The developer console (ScriptManager) is intended for pack developers to debug their Lua scripts and pack definitions. Infrastructure subsystem messages from Voice Recognition, NDI, and MCP were leaking into it via the Serilog DeveloperConsoleSink, confusing users with errors unrelated to their packs (e.g. PortAudio enumeration failures, NDI init warnings). Changes: - DeveloperConsoleSink now filters out log messages prefixed with [Voice], [NDI], or [MCP]. These still go to the file log and stdout. - NdiSendContainer.OnAttachedToVisualTree wrapped in try-catch so NDI init/runtime errors are caught and logged rather than propagating. - NdiSendContainer.Dispose NDI cleanup wrapped in try-catch to prevent exceptions during teardown from surfacing. Closes #37 Co-Authored-By: Claude Opus 4.6 <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
Pack load performance optimizations
List.IndexOfinGetPersistableLocationReference/GetPersistableItemReferencewith O(1) dictionary lookup. Eliminates ~2.9s of O(n²) work during voice command building (583 location lookups).BuildCommandMap(~5s) now snapshots item/location data and runs onTask.Run()with cancellation support, completely off the main thread critical path.BuildCodeIndex()maps code strings to their provider items. Non-Lua items expose static code sets viaGetAllProvidedCodes().ProviderCountForCodeand related methods use the index, only falling back to brute-force for dynamic LuaItems.Profiled with dotnet-trace on the Codetracker Standard Map Tracker pack. Main thread pack load time dropped from ~7.8s to sub-sampling-interval (<10ms visible in profiler).
Developer console cleanup (closes #37)
[Voice]), NDI ([NDI]), and MCP ([MCP]) log messages are excluded from the developer console Serilog sink. These are infrastructure concerns, not relevant to pack developers. They still go to the file log and stdout.NdiSendContainer.OnAttachedToVisualTreeandDisposenow wrap NDI native calls in try-catch so PortAudio/NDI errors are caught and logged rather than propagating to the developer console.Test plan
🤖 Generated with Claude Code