Skip to content

Improve getBlockState performance#4727

Open
Mqrius wants to merge 1 commit intoGregTechCEu:1.20.1from
Mqrius:hot-path-optimization
Open

Improve getBlockState performance#4727
Mqrius wants to merge 1 commit intoGregTechCEu:1.20.1from
Mqrius:hot-path-optimization

Conversation

@Mqrius
Copy link
Contributor

@Mqrius Mqrius commented Mar 7, 2026

What

GT's LevelMixin makes every getBlockState call 6% slower.

The mixin exists to allow multiblock validation to happen off-thread. However, the cheap early exits are hidden behind some bitshifts and indirection.

Since getBlockState is a very hot path, fast exits should be frontloaded as much as possible, even at the cost of code duplication.

This PR moves the most important fast exit to the front.

Implementation Details

I placed the thread check before the clientside check to prioritizing server speed over client speed, though the difference is minimal; both are fast checks.

Outcome

getBlockState runs faster.

How Was This Tested

Game compiles and runs, multiblocks still form.

Additional Information

This is more of a quick fix than a proper solution. Even with this fix, the mixin still causes a CallbackInfoReturnable object to be generated for every getBlockState call, which is not that fast either.

Ultimately these mixin injections should not exist at all. The caller (multiblock validator) always already knows that it's the multiblock validator, that it should run async. The caller should not be calling getBlockState, it should be calling a dedicated getBlockStateAsync method. This would not pollute the vanilla getBlockState method with any mixin at all, so there would be zero slowdown.

Potential Compatibility Issues

Nothing changed logic-wise.

@Mqrius Mqrius requested a review from a team as a code owner March 7, 2026 20:28
@github-actions github-actions bot added the 1.20.1 label Mar 7, 2026
@YoungOnionMC YoungOnionMC added type: bugfix General bug fixes Release: Patch - 0.0.X Smaller changes that either are bug fixes or very minor tweaks. labels Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.20.1 Release: Patch - 0.0.X Smaller changes that either are bug fixes or very minor tweaks. type: bugfix General bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants