Repository navigation
Conversation
SwitchAttributeNode deep-copied the tree node, metatables kept. The node holds a ModList, and copying its class proxies wrote through their __newindex into the ModList of the tree every spec shares, so each copy reached more than the one before. Loading builds with attribute choices again and again could take gigabytes of memory. A shallow copy is enough: ReplaceNode and ProcessStats give it its own stats and mods.
Wires77
approved these changes
Dec 2, 2026
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.
Description of the problem being solved:
PassiveSpecClass:SwitchAttributeNode(src/Classes/PassiveSpec.lua) builds the attribute override node with a deep copy of the tree node, metatables kept:self.tree.nodes[nodeId]belongs to the passive tree, whichmain:LoadTreecaches and every spec and build shares. The node holds aModList, a class instance. The class system gives each instance parent proxies (object.ModStore) whose metatable is the proxy itself, with__newindex = object.copyTableSafesets the original metatable on the copy first and then fills it in without[k] = v, so for these proxies every field it copies goes through__newindexinto the original instance: the shared tree node'smodListgains raw__call,__index,__newindex,_className,_objectand_parentfields that point at the copies.The next switch copies those too, so each copy reaches more than the one before. Every attribute node click with the attribute dialog, every attribute hotkey and every load of a build with attribute choices goes through this function, so the shared tree keeps growing for the whole session.
Effect
newBuild+ loading the build's XML, plain PoB code) took memory to between 3 and 12 GB in some runs, usually by the 7th load. The time was spent inSwitchAttributeNode→copyTableSafe→wipeTable(subTableMap).When this was introduced
The deep copy came with attribute node switching in #14 (2024-12-21). It is in
masterand in v0.23.1 too.The fix
A shallow copy, metatable kept:
A deep copy is not needed.
ReplaceNodethen replaces the copy'sdn,sd,mods,modKey,modList,icon,overlay,keystoneMod,activeEffectImageandreminderTextwith the chosen option's, andProcessStatsgives it a newmodsandModList. The other fields are shared with the tree node and are only read:options,linked, the position fields and so on. The override nodes inhashOverridesare only read afterwards:ReplaceNodecopies them onto the spec's nodes, and saving reads theirdn.ProcessStatsmay split multi-linesdentries in place, but the options'sdwere already processed when the tree loaded, so that changes nothing.Steps taken to verify a working solution:
spec/System/TestPassiveSpec_spec.lua. It switches an allocated attribute node's attribute seven times and checks that the tree node'sModListhas the same raw fields as before, and that the override ends up as Intelligence with+5 to Intelligence. It fails without the fix (not ok 28) and passes with it. The full suite passes: all 904 tests (docker test image).Link to a build that showcases this PR:
Any build with attribute nodes allocated, for example a new character with a few attribute nodes switched to Dexterity or Intelligence.
Before screenshot:
Not visual. Before, after a few switches of the same attribute node, the shared tree node's
modListhas raw__call __index __newindex _className _object _parentfields, which only itsModStoreproxy had before.After screenshot:
Not visual. After, the shared tree node's
modListkeeps exactly the fields it had when the tree loaded.