Repository: bevyengine/bevy
File: crates/bevy_pbr/src/render/light.rs (Rust)

Code before:
                }

                let Some(material_instance) = render_material_instances.instances.get(&main_entity)
                else {
                    continue;
                };
                let Some(material) = render_materials.get(material_instance.asset_id) else {
                    continue;
                };

                let depth_only_draw_function = material
                    .properties
                    .get_draw_function(ShadowsDepthOnlyDrawFunction);
                let material_bind_group_index = if Some(*draw_function) == depth_only_draw_function
                {
                    None
                } else {
                    Some(material.binding.group.0)
                };

                let (vertex_slab, index_slab) =
                    mesh_allocator.mesh_slabs(&mesh_instance.mesh_asset_id);

                let batch_set_key = ShadowBatchSetKey {
                    pipeline: *pipeline_id,
                    draw_function: *draw_function,
                    material_bind_group_index,
                    vertex_slab: vertex_slab.unwrap_or_default(),
                    index_slab,
                };

                shadow_phase.add(
                    batch_set_key,
                    ShadowBinKey {
                        asset_id: mesh_instance.mesh_asset_id.into(),
                    },
                    (entity, main_entity),
                    mesh_instance.current_uniform_index,
                    BinnedRenderPhaseType::mesh(
                        mesh_instance.should_batch(),
                        &gpu_preprocessing_support,
                    ),
                    *current_change_tick,
                );
            }
        }
    }
}

pub struct Shadow {
    /// Determines which objects can be placed into a *batch set*.

Review comment (performance):
DrawFunctionId is Copy, i think you can match on &draw_function to avoid the derefs in the loop body here and have slightly cleaner struct init. (CachedRenderPipelineId also is Copy and can probably save the deref above too)

Code after:

                let Some(material_instance) = render_material_instances.instances.get(&main_entity)
                else {
                    continue;
                };
                let Some(material) = render_materials.get(material_instance.asset_id) else {
                    continue;
                };

                let depth_only_draw_function = material
                    .properties
                    .get_draw_function(ShadowsDepthOnlyDrawFunction);
                let material_bind_group_index = if Some(draw_function) == depth_only_draw_function {
                    None
                } else {
                    Some(material.binding.group.0)
                };

                let (vertex_slab, index_slab) =
                    mesh_allocator.mesh_slabs(&mesh_instance.mesh_asset_id);

                let batch_set_key = ShadowBatchSetKey {
                    pipeline: pipeline_id,
                    draw_function,
                    material_bind_group_index,
                    vertex_slab: vertex_slab.unwrap_or_default(),
                    index_slab,
                };

                shadow_phase.add(
                    batch_set_key,
                    ShadowBinKey {
                        asset_id: mesh_instance.mesh_asset_id.into(),
                    },
                    (entity, main_entity),
                    mesh_instance.current_uniform_index,
                    BinnedRenderPhaseType::mesh(
                        mesh_instance.should_batch(),
                        &gpu_preprocessing_support,
                    ),
                    current_change_tick,
                );
            }
        }
    }
}

pub struct Shadow {
    /// Determines which objects can be placed into a *batch set*.
    ///
    /// Objects in a single batch set can potentially be multi-drawn together,