perf: avoid rescanning predecessors on removal - #229
Open
anaibol wants to merge 1 commit into
Open
Conversation
Author
|
@endel can you take a look into this please? |
Member
|
Hi @anaibol, sorry for lack of response here - thanks for your PR, I'm about to release version Colyseus 0.18 + schemas 5.0 and this issue has been addressed differently on that version! If you can upgrade already, 0.18 is currently in preview, but it should be released this week! |
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.
Summary
Why
Root.remove recursively removes every ChangeTree in a detached subtree. The previous updatePositionsAfterRemoval implementation walked from the list head for every removed node even though predecessor positions cannot change. With many long-lived schemas before a removed nested actor, removal cost therefore scales with both the preceding list and removed subtree.
Starting at node.next makes the work proportional only to actual successors. Tail removals require no position traversal. This does not change the wire format or removal semantics.
Benchmark
Node 22.23.1, five runs, 2,000 preceding branches with 24 nested leaves each and one removed branch with 24 leaves:
The regression test fails on master because predecessor links are revisited and passes with this change.
Verification