Skip to content

Mark the chunk textures changed only when their authored maps are replaced - #3201

Closed
RestartFU wants to merge 1 commit into
devfrom
perf/chunk-textures-change-only-when-replaced
Closed

RestartFU wants to merge 1 commit into
devfrom
perf/chunk-textures-change-only-when-replaced

Conversation

@RestartFU

@RestartFU RestartFU commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Measured: small, about 0.5 µs per frame on each thread (details below).

update_authored_textures runs every frame. It passed its ResMut<ChunkTextureAssets> to apply as &mut, which goes through DerefMut and marks the resource changed, even though apply then found the authored maps unchanged and wrote nothing.

ChunkTextureAssets is extracted to the render world with ExtractResourcePlugin. So on every frame, including idle ones, extraction cloned it into the render world again and marked it changed there, and every render system reacting to that change ran again. An extract-dirtiness measurement on the idle flat world found it marked changed on 99% of frames, with nothing about the textures changing.

The system now checks whether the maps differ before taking the resource mutably, and only takes it mutably to replace them. apply and its tests are unchanged.

Test: render_mode::authored_textures::tests::unchanged_maps_leave_the_chunk_textures_unchanged runs the system three times with nothing to change. It asserts the resource counts as changed only on the first run, when it is inserted.

Measured in Cinnabar's flat-world benchmark, 960×540, on an A/B build with the change switched on and off live. Under the shared benchmark lock, 32 interleaved 4 s pairs over 4 rounds:

  • Main-thread CPU fell by a median 0.56 µs per frame (IQR -0.38 to 2.17).
  • Render-thread CPU fell by 0.50 µs per frame (IQR -0.47 to 2.64), and fps rose by 10.
  • Rounds 3 and 4 were tight at 0-0.4 µs per frame.

Most of the saving is the per-frame extraction clone. Render-side work reacting to the changed textures is small.

Co-Authored-By: Dylan T. 14214667+dktapps@users.noreply.github.com

Summary by CodeRabbit

  • Bug Fixes
    • Unchanged texture updates no longer trigger unnecessary asset changes.

…laced

update_authored_textures borrowed ChunkTextureAssets mutably on every frame, even when the
authored maps were unchanged, which marked the resource changed every frame and made the
render world extract it again each time. It now borrows it mutably only to replace the maps.

Co-Authored-By: Dylan T. <14214667+dktapps@users.noreply.github.com>
@RestartFU RestartFU added the performance Faster or lighter, same behaviour label Nov 26, 2026
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Authored texture updates now check whether map sets are unchanged before applying texture assets. A system test checks whether ChunkTextureAssets is marked changed across three updates.

Changes: Authored texture updates

Layer / File(s) Summary
Map comparison and change tracking
app/src/render_mode/authored_textures.rs
maps_unchanged checks whether two map sets share the same Arc, or are both absent. apply and update_authored_textures avoid replacing assets when maps are unchanged. A system test expects change status [true, false, false] across three updates.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested labels: performance

Suggested reviewers: hashimthearab

Merge Risk: Minimal · up to eac95

This change stops the authored texture resource from being marked changed on idle frames, which avoids repeated extraction to the render world. The comparison logic is unchanged and a test covers the behavior, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: ChunkTextureAssets is marked changed only when the authored maps are replaced. The raw summary says maps_unchanged now compares Arc identity, apply replaces texture a…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title states the main change: ChunkTextureAssets is marked changed only when the authored maps are replaced. The raw summary says maps_unchanged now compares Arc identity, apply replaces texture assets only when the check fails, and update_authored_textures avoids a mutable borrow for unchanged results. The objectives confirm the aim of avoiding changed-marking on idle frames. The title is specific and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b7efff2-fb8e-4968-859b-ab033e95d661
Commits

Reviewing files that changed from the base of the PR and between 8ae394f and eac95f2.

Files selected for processing: 1

  • app/src/render_mode/authored_textures.rs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Faster or lighter, same behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant