Skip to content

Performance quickly drops when using get_mut on Assets<StandardMaterial> #19035

Open
@hukasu

Description

@hukasu

Bevy version

cd67bac

[Optional] Relevant system information

2025-05-02T22:45:58.598136Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux (NixOS 24.11)", kernel: "6.6.85", cpu: "Intel(R) Core(TM) i7-14700KF", core_count: "20", memory: "31.2 GiB" }
2025-05-02T22:45:58.806113Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 4060 Ti", vendor: 4318, device: 10243, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "565.77", backend: Vulkan }

What you did

fn touch_mutably<A: Asset>(mut assets: ResMut<Assets<A>>) {
    for _ in assets.iter_mut() {}
}

What went wrong

Frequency that i can touch_mutably per second decreases rapidly

Investigation

The following issues already report this or something similar

While trying to create a test to see if it is possible to detect these problems programmatically i hit something, the length of MaterialBindGroupBindlessAllocator::slabs and the number of MaterialBindlessSlab::allocated_resource_count quickly grows.

2025-05-02T23:20:00.001547Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 1, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 1014 }
2025-05-02T23:20:00.027122Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 1, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 2028 }
2025-05-02T23:20:00.060859Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 2, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 3042 }
2025-05-02T23:20:00.093389Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 2, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 4034 }
2025-05-02T23:20:00.136316Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 3, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 5060 }
2025-05-02T23:20:00.164971Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 3, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 6038 }
<time skip>
2025-05-02T23:20:14.532212Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 83, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 167384 }
2025-05-02T23:20:14.671118Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 83, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 168362 }
2025-05-02T23:20:14.803780Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 84, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 169388 }
2025-05-02T23:20:14.943487Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 84, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 170390 }
2025-05-02T23:20:15.088701Z  INFO get_mut_leak: Log RenderAppStatistics { render_mesh_asset_count: 20, mesh_allocator_slabs: 3, mesh_allocator_size: 63754272, standard_material_prepared_asset_count: 1002, standard_material_bindless_allocator_slab_count: 85, standard_material_bindless_allocator_slab_capacity: 2048, standard_material_bindless_allocator_total_allocated_resources: 171392 }

on this example there are 1001 StandardMaterials, and i touch all of them per update (see method on What you did section), i did not look at the log in its entirety but it looks like the number of slabs increase every 2 updates with this setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-BugAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile times

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions