Open TreaBeardGaming opened 5 months ago
Hey, thanks for the detailed analysis! I started using quadtrees for organizing items in 2d space (i.e. on a grid) which fixed some of the issues from earlier, but apparently comes with a performance cost. I think I'll put together a benchmarking scene and try to figure out which parts of automerge
and autosplitmerge
can be optimized further.
I did a few optimizations and bugfixes in v2.4.9 but I'm afraid that it only improves performance to some degree. The optimizations mostly affect the "automerge" and "autosplitmerge" calls, while i don't think there's much I can do regarding sort()
since it's generally an expensive operation. But maybe making only once sort()
call after all items have been added could be an acceptable workaround in your case?
On the bright side, the issue where the application gets totally stuck should be fixed now 🙂.
I'll keep this issue open as I don't think the work is really done here (as it never is with optimizations). I'll try to come up with even more tricks to make the grid-based operations faster and report the progress here.
There is a performance impact on .autosplitmerge() and .sort() v2.4.9
Scenario would be adding multiple items per second to inventory.
Using autosplitmerge() from one inventory to another:
Using .sort() on an inventory using autosplitmerge and sorting after every item is merged:
Using automerge() from one inventory to another:
Using .sort() on an inventory using automerge and sorting after every item is merged:
TLDR in my testing:
Using .sort() after every item addition is probably bad move for your game project, don't do it. Using automerge works perfectly fine in low volume, try not to add 20 items a second if it can be avoided. Using autosplitmerge works great as it merges items and fills any stacks that are not full, but has a huge performance impact so use sparingly.