Less repeatedly spawning item groups when checking consistency #72064
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
Performance "Less repeatedly spawning item groups when checking consistency"
Purpose of change
Fix #71371
I noticed that the flame graph of
item_group::check_consistency
can be divided into two blocks that are similar in shapes. That makes me guess that some groups are spawned multiple times. In fact there's too much unnecessary spawning. We actually do not need to spawn everything over and over if there's no container to restrain them.Describe the solution
Introduce a bool parameter
actually_spawn
to the callstack of check_consistency(). The logic below stands on the point that spawning is different from checking consistency. Every item groups and single item creators get their consistency checked, so there's unlikely to be omissions.Describe alternatives you've considered
collection
type item groups automatically spawn all entries when checking consistency, so unless the item group's type isdistribution
, there's no need to spawn all entries individually. ( this is what the first commit does )Gains from this alternative:
Not as seductive as the the main solution, but I think it's less likely to introduce problems.
Testing
It reduces the time spent on verifying items from 12ish seconds to 2ish seconds.
before:
( note the
item_group::check_consistency
line )after:
I also randomly fiddled with some itemgroups to ensures that their errors can still be detected by new code.
Additional context