Skip to content

Improve falling tree performance and consistency on tree scan#1112

Open
avavakin wants to merge 6 commits into
RakambdaOrg:minecraft/26.1.2from
avavakin:av--improve-falling-tree-performance-and-consistency-on-tree-scan
Open

Improve falling tree performance and consistency on tree scan#1112
avavakin wants to merge 6 commits into
RakambdaOrg:minecraft/26.1.2from
avavakin:av--improve-falling-tree-performance-and-consistency-on-tree-scan

Conversation

@avavakin
Copy link
Copy Markdown

Improve falling tree performance and consistency on tree scan

1. Frequently used tree extremums cached:

  • getTopMostLog
  • getBottomMostLog
  • getStart

they are updated only when new part added
retrieval is O(1) instead of O(n)

2. Tree builds only once

Created TreeHandlerState to build tree only once for one event without rebuling it

Reasons:

  • performance improvements (both CPU and memory)
  • consistency: in case of introduction multithreading in mod platforms or Minecraft itself we would have a risk of passing validation shouldCancelEvent and breaking tree breakTree could build different trees in rare circumstances

@avavakin avavakin requested a review from a team as a code owner May 12, 2026 17:29
Comment thread common/src/main/java/fr/rakambda/fallingtree/common/tree/Tree.java Outdated
av and others added 3 commits May 13, 2026 22:57
…ing on `addPart` (lazy-init)

refactored: commited interface separation to make accessible mutation methods visible to TreeBuilder only; secured immutability of `parts` set by exposing only stream of parts in interface
@Rakambda
Copy link
Copy Markdown
Member

I did a little bit of refactoring/changes :

  • TreeHandlerState : wasn't a big fan of it, what actually happened is that the create method was more of a factory for the treeHandler that now contains its own state to perform actions. It's purely a naming thng, doesn't change the logic.
    • The new create method is part of the factory
  • For the mutable tree, instead of abstracting its behavior with an interface, also make a class that only exposes the actual immutable behavior. This avoids a potential cast back to MutableTree later on.
  • Refactor caching logic to avoid duplication.

If that's fine with you, we can merge the PR.

Rakambda
Rakambda previously approved these changes May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants