-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize loading of pockets with many items inside #68051
Optimize loading of pockets with many items inside #68051
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Bless you saint Kamayana, goddes of optimization 🙏 |
The size of items could change between serialization and deserialization due to JSON changes so I think you should test what happens in that case. Ideally the items should spill out of the pocket but I suppose it's fine to keep them inside the pocket as long as it does not generate any errors. |
Tested it, the container will sit in the world undisturbed until the player picks it up, which will spill the items out. No errors. However, if the container is non-rigid and wearable, examining it will show the "volume exceeds capacity" error from |
Stress tested this and saw no CPU impact
Summary
Performance "Optimize loading of pockets with many items inside"
Purpose of change
When pockets have a large number of items inside the game can take a very long time to load them, as the game runs a
can_contain
check on every individual item inside, each of which checks against all the other items inside, giving it an exponential complexity growth.Describe the solution
Use the simplified
can_contain
check created in #67631 to greatly reduce the processing time of thecombine
initem::deserialize
. This simplified check ignores other contents of the pocket and only checks if the item could fit in the pocket even if it were empty. There's not really a reason to do the more intensivecan_contain
check, since if it was invalid it would've been handled before getting serialized in the first place.Describe alternatives you've considered
It's possible there are other calls of
can_contain
that could use the simplified version, but I'm just doing it on a case-by-case basis for whatever needs optimization.Testing
This save has a pocket universe filled with 100,000 pills: Long Load-trimmed.tar.gz
Additional context