findAll: defer slips initialization (~20MB RAM savings)#2539
Open
christopherkmoore wants to merge 1 commit into
Open
findAll: defer slips initialization (~20MB RAM savings)#2539christopherkmoore wants to merge 1 commit into
christopherkmoore wants to merge 1 commit into
Conversation
The `slips.storages:map()` call at module level iterates every storage slip ID and accesses `res.items[id]` for each, forcing Windower's lazy-loading resource system to materialize a large portion of the item database into memory (~20MB). Defer this initialization to the first `search()` call. The slips order only needs to be built once and is cached for subsequent searches. Cold `res.items[id]` lookups benchmark at ~0.2ms each, so the first search has negligible additional latency. Idle memory drops from ~27MB to ~700KB. For multiboxers running 6+ clients this saves ~150MB+ of RAM across all instances.
Author
|
I didn't do too much testing on this other than works on my machine. Claude helped me clean this up and it seems sensible with much better memory footprint after his change -- so I'll leave it up to you all to decide. |
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
slips.storages:map()from module load time to firstsearch()callres.itemsentries from materializing into memory at addon loadProblem
At module level (line 195-198), findAll iterates every storage slip ID and accesses
res.items[id]for each to buildmerged_storages_orders. This forces Windower's lazy-loading resource system to materialize hundreds of item entries into memory (~20MB).This data is only needed when performing a search, not at idle.
Solution
Wrap the slips order initialization in
ensure_merged_storages_orders(), called at the top ofsearch(). Built once on first search, cached for subsequent searches.Impact
res.itemslookups (imperceptible)Testing
//findallsearches return correct results across all storage types including slipsres.items[id]lookups at ~0.2ms each (1000 lookups in 235ms)