ronantakizawa/codereview-bench huggingface dataset:
Repository: bevyengine/bevy
File: examples/3d/meshlet.rs (Rust)

Code before:
//! Meshlet rendering for dense high-poly scenes (experimental).

// Note: This example showcases the meshlet API, but is not the type of scene that would benefit from using meshlets.

#[path = "../helpers/camera_controller.rs"]
mod camera_controller;

use bevy::{
    light::{CascadeShadowConfigBuilder, DirectionalLightShadowMap},
    pbr::experimental::meshlet::{MeshletMesh3d, MeshletPlugin},
    prelude::*,
    render::render_resource::AsBindGroup,
};
use camera_controller::{CameraController, CameraControllerPlugin};
use std::f32::consts::PI;

const ASSET_URL: &str =
    "https://raw.githubusercontent.com/atlv24/assets/69bb39164fd35aadf863f6009520d4981eafcea0/bunny.meshlet_mesh";

fn main() {
    App::new()
        .insert_resource(DirectionalLightShadowMap { size: 4096 })
        .add_plugins((
            DefaultPlugins,
            MeshletPlugin {
                cluster_buffer_slots: 1 << 14,
            },
            MaterialPlugin::<MeshletDebugMaterial>::default(),
            CameraControllerPlugin,
        ))
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut standard_materials: ResMut<Assets<StandardMaterial>>,
    mut debug_materials: ResMut<Assets<MeshletDebugMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
) {
    commands.spawn((
        Camera3d::default(),

Review comment (suggestion):
```suggestion
    "https://github.com/bevyengine/bevy_asset_files/raw/9bf88c42b9d06a3634eed633d90ce5fab02c31da/meshlet/bunny.meshlet_mesh";
```

Code after:
//! Meshlet rendering for dense high-poly scenes (experimental).

// Note: This example showcases the meshlet API, but is not the type of scene that would benefit from using meshlets.

#[path = "../helpers/camera_controller.rs"]
mod camera_controller;

use bevy::{
    light::{CascadeShadowConfigBuilder, DirectionalLightShadowMap},
    pbr::experimental::meshlet::{MeshletMesh3d, MeshletPlugin},
    prelude::*,
    render::render_resource::AsBindGroup,
};
use camera_controller::{CameraController, CameraControllerPlugin};
use std::f32::consts::PI;

const ASSET_URL: &str =
    "https://github.com/bevyengine/bevy_asset_files/raw/9bf88c42b9d06a3634eed633d90ce5fab02c31da/meshlet/bunny.meshlet_mesh";

fn main() {
    App::new()
        .insert_resource(DirectionalLightShadowMap { size: 4096 })
        .add_plugins((
            DefaultPlugins,
            MeshletPlugin {
                cluster_buffer_slots: 1 << 14,
            },
            MaterialPlugin::<MeshletDebugMaterial>::default(),
            CameraControllerPlugin,
        ))
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut commands: Commands,
    asset_server: Res<AssetServer>,
    mut standard_materials: ResMut<Assets<StandardMaterial>>,
    mut debug_materials: ResMut<Assets<MeshletDebugMaterial>>,
    mut meshes: ResMut<Assets<Mesh>>,
) {
    commands.spawn((
        Camera3d::default(),
Repository: bevyengine/bevy
File: crates/bevy_pbr/src/volumetric_fog/mod.rs (Rust)

Code before:
            .insert_resource(FogAssets {
                plane_mesh,
                cube_mesh,
            })
            .init_resource::<SpecializedRenderPipelines<VolumetricFogPipeline>>()
            .init_resource::<VolumetricFogUniformBuffer>()
            .add_systems(RenderStartup, init_volumetric_fog_pipeline)
            .add_systems(ExtractSchedule, render::extract_volumetric_fog)
            .add_systems(
                Render,
                (
                    render::prepare_volumetric_fog_pipelines.in_set(RenderSystems::Prepare),
                    render::prepare_volumetric_fog_uniforms.in_set(RenderSystems::Prepare),
                    render::prepare_view_depth_textures_for_volumetric_fog
                        .in_set(RenderSystems::Prepare)
                        .before(prepare_core_3d_depth_textures),
                ),
            )
            .add_render_graph_node::<ViewNodeRunner<VolumetricFogNode>>(
                Core3d,
                NodePbr::VolumetricFog,
            )
            .add_render_graph_edges(
                Core3d,
                // Volumetric fog is a postprocessing effect. Run it after the
                // main pass but before bloom.
                (
                    Node3d::EndMainPass,
                    NodePbr::VolumetricFog,
                    Node3d::StartMainPassPostProcessing,
                ),
            );
    }
}


Review comment (suggestion):
```suggestion
                // main pass but before post processing.
```

Code after:
            .insert_resource(FogAssets {
                plane_mesh,
                cube_mesh,
            })
            .init_resource::<SpecializedRenderPipelines<VolumetricFogPipeline>>()
            .init_resource::<VolumetricFogUniformBuffer>()
            .add_systems(RenderStartup, init_volumetric_fog_pipeline)
            .add_systems(ExtractSchedule, render::extract_volumetric_fog)
            .add_systems(
                Render,
                (
                    render::prepare_volumetric_fog_pipelines.in_set(RenderSystems::Prepare),
                    render::prepare_volumetric_fog_uniforms.in_set(RenderSystems::Prepare),
                    render::prepare_view_depth_textures_for_volumetric_fog
                        .in_set(RenderSystems::Prepare)
                        .before(prepare_core_3d_depth_textures),
                ),
            )
            .add_render_graph_node::<ViewNodeRunner<VolumetricFogNode>>(
                Core3d,
                NodePbr::VolumetricFog,
            )
            .add_render_graph_edges(
                Core3d,
                // Volumetric fog should run after the main pass but before bloom, so
                // we order if at the start of post processing.
                (
                    Node3d::EndMainPass,
                    NodePbr::VolumetricFog,
                    Node3d::StartMainPassPostProcessing,
                ),
            );
    }
}
Repository: bevyengine/bevy
File: examples/ui/standard_widgets_observers.rs (Rust)

Code before:
//! This example illustrates how to create widgets using the `bevy_ui_widgets` widget set.

use bevy::{
    color::palettes::basic::*,
    ecs::system::SystemId,
    input_focus::{
        tab_navigation::{TabGroup, TabIndex, TabNavigationPlugin},
        InputDispatchPlugin,
    },
    picking::hover::Hovered,
    prelude::*,
    ui::{Checked, InteractionDisabled, Pressed},
    ui_widgets::{
        Activate, ButtonBehavior, Callback, CheckboxBehavior, SliderBehavior, SliderRange,
        SliderThumb, SliderValue, ValueChange, WidgetBehaviorPlugins,
    },
};

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            WidgetBehaviorPlugins,
            InputDispatchPlugin,
            TabNavigationPlugin,
        ))

Review comment (performance):
This is a bit tangential to the scope of this PR, but I think it might be prudent to brand `bevy_ui_widgets` as "experimental" for a release, in the same vein as bevy_feathers:

1. I'm still planning on advocating for using Observers instead of Callbacks in the next cycle. I think the existence of both concepts is unnecessary additional complexity. These are "events", and observers are Bevy's "event handlers".
2. Currently we're in an awkward middle ground where you need to choose between polling systems (which isn't our API-end-game) or the ergonomics embarrassment that is the `standard_widgets_observers.rs` example (I actually think removing it makes sense, as we don't want to encourage people to adopt this pattern in its current form, and examples exist to show people patterns they should adopt). Billing the current state of things as "ready" / "the full release" doesn't feel great to me.

Code after:
//! This example illustrates how to create widgets using the `bevy_ui_widgets` widget set.

use bevy::{
    color::palettes::basic::*,
    ecs::system::SystemId,
    input_focus::{
        tab_navigation::{TabGroup, TabIndex, TabNavigationPlugin},
        InputDispatchPlugin,
    },
    picking::hover::Hovered,
    prelude::*,
    ui::{Checked, InteractionDisabled, Pressed},
    ui_widgets::{
        Activate, Button, Callback, Checkbox, Slider, SliderRange, SliderThumb, SliderValue,
        ValueChange, WidgetBehaviorPlugins,
    },
};

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins,
            WidgetBehaviorPlugins,
            InputDispatchPlugin,
            TabNavigationPlugin,
        ))
Repository: bevyengine/bevy
File: crates/bevy_reflect/src/is.rs (Rust)

Code before:
use core::any::{Any, TypeId};

/// Checks if the current type "is" another type, using a [`TypeId`] equality comparison.
pub trait Is {
    /// Checks if the current type "is" another type, using a [`TypeId`] equality comparison.
    /// This is most useful in the context of generic logic.
    ///
    /// ```
    /// # use bevy_reflect::Is;
    /// fn greet_if_u32<T: Any>() {
    ///     if T::is::<u32>() {
    ///         println!("Hello");
    ///     }
    /// }
    /// // this will print "Hello"
    /// greet_if_u32::<u32>();
    /// // this will not print "Hello"
    /// greet_if_u32::<String>();
    /// assert!(u32::is::<u32>());
    /// assert!(!usize::is::<u32>());
    /// ```
    fn is<T: Any>() -> bool;
}

impl<A: Any> Is for A {
    #[inline]
    fn is<T: Any>() -> bool {
        TypeId::of::<A>() == TypeId::of::<T>()
    }
}


Review comment (suggestion):
```suggestion
    /// # use bevy_reflect::Is;
    /// # use std::any::Any;
```

Code after:
use core::any::{Any, TypeId};

/// Checks if the current type "is" another type, using a [`TypeId`] equality comparison.
pub trait Is {
    /// Checks if the current type "is" another type, using a [`TypeId`] equality comparison.
    /// This is most useful in the context of generic logic.
    ///
    /// ```
    /// # use bevy_reflect::Is;
    /// # use std::any::Any;
    /// fn greet_if_u32<T: Any>() {
    ///     if T::is::<u32>() {
    ///         println!("Hello");
    ///     }
    /// }
    /// // this will print "Hello"
    /// greet_if_u32::<u32>();
    /// // this will not print "Hello"
    /// greet_if_u32::<String>();
    /// assert!(u32::is::<u32>());
    /// assert!(!usize::is::<u32>());
    /// ```
    fn is<T: Any>() -> bool;
}

impl<A: Any> Is for A {
    #[inline]
    fn is<T: Any>() -> bool {
        TypeId::of::<A>() == TypeId::of::<T>()
    }
}
Repository: bevyengine/bevy
File: crates/bevy_ui/src/ui_transform.rs (Rust)

Code before:
    #[inline]
    pub fn affine(&self) -> Affine2 {
        self.0
    }
}

impl From<Affine2> for UiGlobalTransform {
    fn from(value: Affine2) -> Self {
        Self(value)
    }
}

impl From<UiGlobalTransform> for Affine2 {
    fn from(value: UiGlobalTransform) -> Self {
        value.0
    }
}

impl From<&UiGlobalTransform> for Affine2 {
    fn from(value: &UiGlobalTransform) -> Self {
        value.0
    }
}

impl Mul<UiGlobalTransform> for UiGlobalTransform {
    type Output = Affine2;

    #[inline]
    fn mul(self, value: UiGlobalTransform) -> Self::Output {
        self.0 * value.0
    }
}

impl Mul<Affine2> for UiGlobalTransform {
    type Output = Affine2;

    #[inline]
    fn mul(self, affine2: Affine2) -> Self::Output {
        self.0 * affine2
    }
}

impl Mul<Vec2> for UiGlobalTransform {
    type Output = Vec2;

    #[inline]
    fn mul(self, value: Vec2) -> Vec2 {
        self.transform_point2(value)
    }
}


Review comment (suggestion):
Just curious, why is the Output not another `UiGlobalTransform`?

Same with the Affine * UiGlobalTransform.

Code after:
    #[inline]
    pub fn affine(&self) -> Affine2 {
        self.0
    }
}

impl From<Affine2> for UiGlobalTransform {
    fn from(value: Affine2) -> Self {
        Self(value)
    }
}

impl From<UiGlobalTransform> for Affine2 {
    fn from(value: UiGlobalTransform) -> Self {
        value.0
    }
}

impl From<&UiGlobalTransform> for Affine2 {
    fn from(value: &UiGlobalTransform) -> Self {
        value.0
    }
}

impl Mul for UiGlobalTransform {
    type Output = Self;

    #[inline]
    fn mul(self, value: Self) -> Self::Output {
        Self(self.0 * value.0)
    }
}

impl Mul<Affine2> for UiGlobalTransform {
    type Output = Affine2;

    #[inline]
    fn mul(self, affine2: Affine2) -> Self::Output {
        self.0 * affine2
    }
}

impl Mul<UiGlobalTransform> for Affine2 {
    type Output = Affine2;

    #[inline]
    fn mul(self, transform: UiGlobalTransform) -> Self::Output {
        self * transform.0
    }
}
Repository: bevyengine/bevy
File: examples/ui/anchor_layout.rs (Rust)

Code before:
                // fill the entire window
                width: percent(100),
                height: percent(100),
                flex_direction: FlexDirection::Column,
                align_items: AlignItems::Center,
                padding: UiRect::all(MARGIN),
                row_gap: MARGIN,
                ..default()
            },
            BackgroundColor(Color::BLACK),
        ))
        .with_children(|builder| {
            let rows = [
                [
                    (
                        "left/top",
                        Node {
                            left: px(10),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (
                        "center/top",
                        Node {
                            margin: UiRect::horizontal(Val::Auto),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (
                        "right/top",
                        Node {
                            right: px(10),
                            top: px(10),
                            ..default()
                        },
                    ),
                ],
                [
                    (
                        "left/center",
                        Node {
                            left: px(10),
                            margin: UiRect::vertical(Val::Auto),
                            ..default()
                        },
                    ),
                    (
                        "center/center",
                        Node {

Review comment (suggestion):
```suggestion
                            margin: auto().horizontal(),
```

Code after:
            "left: 10px\ntop: 10px",
            Node {
                left: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "center: 10px\ntop: 10px",
            Node {
                margin: auto().horizontal(),
                top: px(10),
                ..default()
            },
        ),
        (
            "right: 10px\ntop: 10px",
            Node {
                right: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "left: 10px\ncenter: 10px",
            Node {
                left: px(10),
                margin: UiRect::vertical(Val::Auto),
                ..default()
            },
        ),
        (
            "center: 10px\ncenter: 10px",
            Node {
                margin: UiRect::all(Val::Auto),
                ..default()
            },
        ),
        (
            "right: 10px\ncenter: 10px",
            Node {
                right: px(10),
                margin: UiRect::vertical(Val::Auto),
                ..default()
            },
        ),
        (
            "left: 10px\nbottom: 10px",
            Node {
                left: px(10),
                bottom: px(10),
Repository: bevyengine/bevy
File: examples/ui/anchor_layout.rs (Rust)

Code before:

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "Bevy Anchor Layout Example".to_string(),
                ..default()
            }),
            ..default()
        }))
        .add_systems(Startup, spawn_layout)
        .run();
}

fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
    commands.spawn(Camera2d);
    commands
        .spawn((
            Node {
                // fill the entire window
                width: percent(100),
                height: percent(100),
                flex_direction: FlexDirection::Column,
                align_items: AlignItems::Center,
                padding: UiRect::all(MARGIN),
                row_gap: MARGIN,
                ..default()
            },
            BackgroundColor(Color::BLACK),
        ))
        .with_children(|builder| {
            let rows = [
                [
                    (
                        "left/top",
                        Node {
                            left: px(10),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (
                        "center/top",
                        Node {
                            margin: UiRect::horizontal(Val::Auto),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (

Review comment (suggestion):
There is a new fluent interface for constructing `UiRect`s in 0.17:

```suggestion
                padding: MARGIN.all(),
```

Code after:

fn main() {
    App::new()
        .add_plugins(DefaultPlugins.set(WindowPlugin {
            primary_window: Some(Window {
                title: "Bevy Anchor Layout Example".to_string(),
                ..default()
            }),
            ..default()
        }))
        .add_systems(Startup, spawn_layout)
        .run();
}

fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
    commands.spawn(Camera2d);

    let rows = [
        (
            "left: 10px\ntop: 10px",
            Node {
                left: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "center: 10px\ntop: 10px",
            Node {
                margin: auto().horizontal(),
                top: px(10),
                ..default()
            },
        ),
        (
            "right: 10px\ntop: 10px",
            Node {
                right: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "left: 10px\ncenter: 10px",
            Node {
                left: px(10),
                margin: UiRect::vertical(Val::Auto),
                ..default()
            },
        ),
Repository: bevyengine/bevy
File: examples/ui/anchor_layout.rs (Rust)

Code before:
        .add_systems(Startup, spawn_layout)
        .run();
}

fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
    commands.spawn(Camera2d);
    commands
        .spawn((
            Node {
                // fill the entire window
                width: percent(100),
                height: percent(100),
                flex_direction: FlexDirection::Column,
                align_items: AlignItems::Center,
                padding: UiRect::all(MARGIN),
                row_gap: MARGIN,
                ..default()
            },
            BackgroundColor(Color::BLACK),
        ))
        .with_children(|builder| {
            let rows = [
                [
                    (
                        "left/top",
                        Node {
                            left: px(10),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (
                        "center/top",
                        Node {
                            margin: UiRect::horizontal(Val::Auto),
                            top: px(10),
                            ..default()
                        },
                    ),
                    (
                        "right/top",
                        Node {
                            right: px(10),
                            top: px(10),
                            ..default()
                        },
                    ),
                ],
                [
                    (

Review comment (suggestion):
These could show the actual layout constraints instead, like:
```
                        "left: px(10),\ntop: px(10)",
```
assuming they can be made to fit.

Code after:
        .add_systems(Startup, spawn_layout)
        .run();
}

fn spawn_layout(mut commands: Commands, asset_server: Res<AssetServer>) {
    let font = asset_server.load("fonts/FiraSans-Bold.ttf");
    commands.spawn(Camera2d);

    let rows = [
        (
            "left: 10px\ntop: 10px",
            Node {
                left: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "center: 10px\ntop: 10px",
            Node {
                margin: auto().horizontal(),
                top: px(10),
                ..default()
            },
        ),
        (
            "right: 10px\ntop: 10px",
            Node {
                right: px(10),
                top: px(10),
                ..default()
            },
        ),
        (
            "left: 10px\ncenter: 10px",
            Node {
                left: px(10),
                margin: UiRect::vertical(Val::Auto),
                ..default()
            },
        ),
        (
            "center: 10px\ncenter: 10px",
            Node {
                margin: UiRect::all(Val::Auto),
                ..default()
            },
        ),
        (
            "right: 10px\ncenter: 10px",
            Node {
Repository: bevyengine/bevy
File: crates/bevy_utils/src/debug_info.rs (Rust)

Code before:
    }

    impl From<String> for DebugName {
        fn from(value: String) -> Self {
            Self::owned(value)
        }
    }

    impl From<DebugName> for Cow<'static, str> {
        #[cfg_attr(
            not(feature = "debug"),
            expect(
                unused_variables,
                reason = "The value will be ignored if the `debug` feature is not enabled"
            )
        )]
        fn from(value: DebugName) -> Self {
            #[cfg(feature = "debug")]
            value.name
        }
    }
}

impl From<&'static str> for DebugName {
    fn from(value: &'static str) -> Self {
        Self::borrowed(value)
    }
}


Review comment (bug):
```suggestion
        fn from(value: DebugName) -> Self {
            #[cfg(feature = "debug")]
            {
                value.name
            }
            #[cfg(not(feature = "debug"))]
            {
                Cow::Borrowed(FEATURE_DISABLED)
            }
        }
```

Code after:
    }

    impl From<String> for DebugName {
        fn from(value: String) -> Self {
            Self::owned(value)
        }
    }

    impl From<DebugName> for Cow<'static, str> {
        #[cfg_attr(
            not(feature = "debug"),
            expect(
                unused_variables,
                reason = "The value will be ignored if the `debug` feature is not enabled"
            )
        )]
        fn from(value: DebugName) -> Self {
            #[cfg(feature = "debug")]
            {
                value.name
            }
            #[cfg(not(feature = "debug"))]
            {
                Cow::Borrowed(FEATURE_DISABLED)
            }
        }
    }
}

impl From<&'static str> for DebugName {
    fn from(value: &'static str) -> Self {
        Self::borrowed(value)
    }
}