Bump version to 0.10.32 and fix memory leaks#161
Open
Axis-qc wants to merge 1 commit into
Open
Conversation
- Add periodic cache cleanup and GC management to prevent sustained memory growth - Fix scripted trigger accumulation: filter ScopedEffect data links from lookup.triggers in STLGame, use eventTargetLinks in VarDefHook across STL/HOI4/EU4/CK2 - Add dataEventTargetLinksCache to avoid redundant computation - Add IGame.ClearResources()/ClearValidationCache() interface with implementations across all 10 game types - Add getMemoryDetails command and memory monitor status bar - Add i18n support via LangResources for memory monitor labels - Update cwtools submodule to include all fixes - Version bump 0.10.31 → 0.10.32 Caveats: - Only tested on Stellaris; HOI4/EU4/CK2 have same fix unconfirmed - Jomini-based games (CK3/VIC3/EU5/IR/VIC2) use shared hooks that also call addDataEventTargetLinks twice per cycle — not yet investigated
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.
Problem
The CWTools language server's memory grows continuously up to 12GB+ during long-running sessions. Root cause:
addDataEventTargetLinks()createsScopedEffectentries withEffectType.ValueTriggerthat leak intolookup.triggers. EachRefreshCachescycle reads these back fromlookup.triggersand appends them again, adding ~430k duplicate trigger entries per cycle — growing from ~200k to over 3M within hours.Changes
1. Trigger accumulation fix (core)
ScopedEffectinstances fromlookup.triggersinrefreshConfigAfterFirstTypesHook— these are data event target links, not real triggers. This breaks the cross-cycle accumulation feedback loop.refreshConfigAfterVarDefHooknow useslookup.eventTargetLinksinstead ofupdateEventTargetLinks + dataEventTargetLinksCache, eliminating intra-cycle ValueTrigger duplication.dataEventTargetLinksCachefield to avoid redundant computation ofaddDataEventTargetLinks.2. Cache cleanup API
ClearResources()/ClearValidationCache()toIGameinterface, implemented across all 10 game types.ResourceManager.Clear()— clearsfileMapandentitiesMap.ErrorCache.Clear()— clears all cached validation errors.3. Memory monitoring
.resxresource files, following the system culture.4. Other
GC.CollectindelayedAnalyze.This PR has NOT been thoroughly tested. Please be aware of the following before merging:
Only Stellaris has been verified. HOI4/EU4/CK2 have the same fix pattern applied (VarDefHook uses
eventTargetLinks), but have NOT been actually tested to confirm trigger count stops growing.ScopedEffect filtering is brittle. The filter in STLGame assumes legitimate triggers are
DocEffectorScriptedEffectinstances, and only data link entries areScopedEffect. If any game defines real triggers asScopedEffect, the filter will incorrectly remove them.Jomini-based games are NOT fixed. CK3 / VIC3 / EU5 / IR / VIC2 share
Hooks.refreshConfigAfterHook, which callsaddDataEventTargetLinksin both first-types and var-def hooks. This likely has the same accumulation issue — not yet investigated.Cache clearing may cause CPU spikes.
ClearResources()drops all parsed ASTs; the next analysis cycle will re-parse everything. Deep cleanup runs every 10 cycles and may cause brief CPU spikes on large projects.GC.Collect overhead. Periodic
GC.Collect(2, GCCollectionMode.Optimized)may increase GC pause times on large projects.Merge Order
This PR depends on a companion PR in the cwtools submodule:
Axis-qc/cwtools fix/memory-leak→cwtools/cwtools master(15 files, +70/−13 lines)cwtools/cwtools-vscode mainThe main repo's
submodules/cwtoolspointer references the new submodule commit. Merging in the wrong order will break the submodule reference.