Skip to content

perf(world_editor): single-traversal write on the default no-override path#1067

Open
rzmo wants to merge 1 commit into
louis-e:mainfrom
rzmo:perf/set-block-single-traversal
Open

perf(world_editor): single-traversal write on the default no-override path#1067
rzmo wants to merge 1 commit into
louis-e:mainfrom
rzmo:perf/set-block-single-traversal

Conversation

@rzmo
Copy link
Copy Markdown

@rzmo rzmo commented May 27, 2026

set_block(..., None, None) is the dominant write pattern across all element processors (~240 callsites). It currently goes through get_block() followed by set_block_with_properties(), descending the region/chunk/section FnvHashMap hierarchy twice per write.

This PR adds WorldToModify::set_with_props_if_absent, a single-traversal variant that does one entry().or_default() descent and checks section.storage.get(idx) == AIR directly. The None/None branch of set_block_with_properties_absolute routes to it via an early-return. The whitelist/blacklist slow path is untouched. Same pattern as the existing set_block_if_absent used by ground_generation.

SectionToModify::get_block returns None iff storage.get(idx) == AIR, so the condition checked is identical to the old path. Behaviour is preserved, only the number of map lookups is halved.

Benchmarked on Munich centre (48.125768,11.552296,48.148565,11.593838) with --terrain --benchmark --file over cached OSM data, release build, 5 runs each:

Mean Median
Before 9925 ms 9916 ms
After 9480 ms 9441 ms
Delta -445 ms (-4.5%) -475 ms (-4.8%)

All five after-runs were faster than all five before-runs.

… path

set_block(..., None, None) is the dominant write pattern across all element
processors (~240 callsites). It previously went through get_block() +
set_block_with_properties(), descending the region/chunk/section FnvHashMap
hierarchy twice per write.

Add WorldToModify::set_with_props_if_absent and route the None/None branch
of set_block_with_properties_absolute through it. A single entry().or_default()
descent checks storage.get(idx) == AIR and writes in one pass.

Benchmarked on Munich city centre (--terrain, cached data, 5 runs each):
  Before: mean 9925 ms, median 9916 ms
  After:  mean 9480 ms, median 9441 ms  (-4.5% / -4.8%)
@rzmo
Copy link
Copy Markdown
Author

rzmo commented May 27, 2026

The benchmark ran successfully but the verdict was "generation time is unchanged" since CI rounds to whole seconds, so the local 4.5% improvement falls below CI's resolution. Can retrigger, I don't mind

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.

1 participant