Avoid unnecessary deep copies to improve generation speed #133
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.
In Archipelago, Super Metroid's
copy_mixin
function showed up in profile results as 145s cumulative time, out of 639s (73 players). Most of that time is indeepcopy
and my analysis showed the majority was spent copying the fieldshelpers
andobjectives
, of which the latter breaks down further intogoals
andgraph
.helpers
just keeps a reference to thesmbm
, so we don't need to create another copy while we're copying, andgraph
is remarked as being something that doesn't change. As such, we can avoid making copies of those;helpers
can point back at the new copy, andgraph
can be the same object.Results:
I wrote and tested this in Archipelago (PR) without a ROM file, so please confirm that this works as expected here, especially as I did not confirm that the graph referenced by Objectives is not modified somewhere deeply hidden in the code, but since this did not break AP generation with the base settings I believe it works right.