perf: optimize bedrock save speed + fix block direction mappings#850
Conversation
Performance:
- Eliminate format!("{:?}") string allocation in palette hot loop (4096x
per section) by using BedrockBlock directly as HashMap key with proper
Hash/Eq impl via BTreeMap for deterministic ordering
- Merge two LevelDB passes into one: blocks + entities written in a
single DB session instead of open→write→close→reopen→write→close
- Remove RustyDBInterface dependency, use raw DB with build_chunk_key_bytes
Bug fixes:
- Fix trapdoor/bed direction mapping: use 0=east,1=west,2=south,3=north
(matching stairs weirdo_direction) instead of incorrect values
- Fix rail shape→rail_direction conversion: was completely missing, all
rails defaulted to north-south. Now converts all 10 shapes including
curved rails (with corrected north curve values 8=NW, 9=NE)
|
⏱️ Benchmark run finished in 0m 35s 📈 Compared against baseline: 30s 📅 Last benchmark: 2026-03-26 23:15:10 UTC You can retrigger the benchmark by commenting |
There was a problem hiding this comment.
Pull request overview
This PR improves Bedrock (.mcworld) world saving performance and corrects several Java→Bedrock block-state mappings, primarily by reducing allocations in palette generation and consolidating LevelDB writes.
Changes:
- Optimize subchunk palette deduplication by using
BedrockBlockas theHashMapkey (with deterministic state ordering) instead offormat!("{:?}")string keys. - Consolidate LevelDB writes into a single DB open/session and write blocks + (block) entities in one pass using a custom chunk-key builder.
- Fix state conversions for trapdoors/beds direction encoding and add rail
shape→rail_directionconversion (including curved rails), updating related tests for bed direction.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/world_editor/bedrock.rs |
Switches Bedrock LevelDB writing to raw rusty_leveldb::DB with a custom chunk key encoder; writes blocks + entities in one pass; optimizes palette dedup key to avoid per-block string allocations. |
src/bedrock_block_map.rs |
Makes BedrockBlock hashable/equatable via deterministic BTreeMap states; fixes trapdoor/bed direction mappings; adds rail shape→rail_direction conversion and updates bed-facing unit tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add tests verifying build_chunk_key_bytes matches the canonical ChunkKey encoding for Version, Data3D, SubChunk, and negative y index - Add tests for all 10 rail shape→rail_direction mappings - Add test for rail default (no properties) fallback
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Performance:
Bug fixes: