Skip to content

perf: optimize bedrock save speed + fix block direction mappings#850

Merged
louis-e merged 2 commits into
mainfrom
perf/bedrock-save-optimizations
Mar 26, 2026
Merged

perf: optimize bedrock save speed + fix block direction mappings#850
louis-e merged 2 commits into
mainfrom
perf/bedrock-save-optimizations

Conversation

@louis-e

@louis-e louis-e commented Mar 26, 2026

Copy link
Copy Markdown
Owner

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)

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)
Copilot AI review requested due to automatic review settings March 26, 2026 23:13
@github-actions

Copy link
Copy Markdown

⏱️ Benchmark run finished in 0m 35s
🧠 Peak memory usage: 1128 MB

📈 Compared against baseline: 30s
🧮 Delta: 5s
🔢 Commit: 296af73

⚠️ This PR worsens generation time.

📅 Last benchmark: 2026-03-26 23:15:10 UTC

You can retrigger the benchmark by commenting retrigger-benchmark.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 BedrockBlock as the HashMap key (with deterministic state ordering) instead of format!("{:?}") 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 shaperail_direction conversion (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 shaperail_direction conversion and updates bed-facing unit tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/world_editor/bedrock.rs
Comment thread src/bedrock_block_map.rs
- 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@louis-e louis-e merged commit c435f28 into main Mar 26, 2026
6 checks passed
@louis-e louis-e deleted the perf/bedrock-save-optimizations branch March 26, 2026 23:44
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