Skip to content

Optimize meshlet material pipeline preparation#23794

Open
CrazyRoka wants to merge 1 commit intobevyengine:mainfrom
CrazyRoka:optimize-meshlet-processing
Open

Optimize meshlet material pipeline preparation#23794
CrazyRoka wants to merge 1 commit intobevyengine:mainfrom
CrazyRoka:optimize-meshlet-processing

Conversation

@CrazyRoka
Copy link
Copy Markdown
Contributor

@CrazyRoka CrazyRoka commented Apr 13, 2026

Objective

  • Reduce CPU overhead in the meshlet renderer by avoiding redundant computations.
  • Optimize prepare_material_meshlet_meshes_main_opaque_pass and prepare_material_meshlet_meshes_prepass performance during the render preparation phase.

Solution

The previous implementation performed expensive computations for every meshlet instance before checking if the resulting pipeline_id was already in the cache.

I refactored the caching logic to check the cache beforehand. The heavy computation is now wrapped inside the cache-miss block.

Testing

  • I used a separate stress test (introduced in Add many_meshlet_materials stress test example #23792) to measure the impact of these changes.
  • The issue happens when unique-materials flag is enabled: cargo run --features=meshlet,https --release --example many_meshlet_materials -- --unique-materials
  • Also compared 3d/meshlet example behavior before and after the fix.

Showcase

Before - 52% CPU usage (Flamegraph)

image

After - 6.7% CPU usage (Flamegraph)

image

@CrazyRoka CrazyRoka force-pushed the optimize-meshlet-processing branch from 14fae7b to 7f65740 Compare April 13, 2026 21:11
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times X-Uncontroversial This work is generally agreed upon D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 13, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Apr 13, 2026
@JMS55
Copy link
Copy Markdown
Contributor

JMS55 commented Apr 14, 2026

Thanks for the PR!

Noting for future reference: The real fix will be to make this retained on each entity, similiar to how the standard Bevy renderer was restructured a few releases ago.

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

Labels

A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

3 participants