bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
34.22k stars 3.34k forks source link

Bevy depends on 4 different versions of the windows crate #11244

Open Veykril opened 6 months ago

Veykril commented 6 months ago

Bevy version

Relevant system information

❯ cargo --version
cargo 1.77.0-nightly (ac6bbb332 2023-12-26)

on windows 10

What's performing poorly?

This is not necessarily a regression, but it was the template that fits best. Bevy currently depends on 4 versions of the windows crate, namely 0.44.0, 0.46.0, 0.48.0 and 0.52.0:

windows v0.44.0
└── gpu-allocator v0.22.0
    └── wgpu-hal v0.17.2
        ├── wgpu v0.17.2
        │   └── bevy_render v0.12.1
        │       ├── bevy_animation v0.12.1
        │       │   ├── bevy_gltf v0.12.1 (*)
        │       │   └── bevy_internal v0.12.1 (*)
        │       ├── bevy_core_pipeline v0.12.1
        │       │   ├── bevy-inspector-egui v0.22.1 (*)
        │       │   ├── bevy_gizmos v0.12.1
        │       │   │   └── bevy_internal v0.12.1 (*)
        │       │   ├── bevy_gltf v0.12.1 (*)
        │       │   ├── bevy_internal v0.12.1 (*)
        │       │   ├── bevy_pbr v0.12.1
        │       │   │   ├── bevy-inspector-egui v0.22.1 (*)
        │       │   │   ├── bevy_gizmos v0.12.1 (*)
        │       │   │   ├── bevy_gltf v0.12.1 (*)
        │       │   │   └── bevy_internal v0.12.1 (*)
        │       │   ├── bevy_sprite v0.12.1
        │       │   │   ├── bevy_gizmos v0.12.1 (*)
        │       │   │   ├── bevy_internal v0.12.1 (*)
        │       │   │   ├── bevy_text v0.12.1
        │       │   │   │   ├── bevy_internal v0.12.1 (*)
        │       │   │   │   └── bevy_ui v0.12.1
        │       │   │   │       └── bevy_internal v0.12.1 (*)
        │       │   │   └── bevy_ui v0.12.1 (*)
        │       │   └── bevy_ui v0.12.1 (*)
        │       ├── bevy_gizmos v0.12.1 (*)
        │       ├── bevy_gltf v0.12.1 (*)
        │       ├── bevy_internal v0.12.1 (*)
        │       ├── bevy_pbr v0.12.1 (*)
        │       ├── bevy_scene v0.12.1
        │       │   ├── bevy_gltf v0.12.1 (*)
        │       │   └── bevy_internal v0.12.1 (*)
        │       ├── bevy_sprite v0.12.1 (*)
        │       ├── bevy_text v0.12.1 (*)
        │       └── bevy_ui v0.12.1 (*)
        └── wgpu-core v0.17.1
            └── wgpu v0.17.2 (*)
windows v0.46.0
└── cpal v0.15.2
    └── rodio v0.17.3
        └── bevy_audio v0.12.1
            └── bevy_internal v0.12.1
                └── bevy v0.12.1
windows v0.48.0
└── accesskit_windows v0.15.1
    └── accesskit_winit v0.15.0
        └── bevy_winit v0.12.1
            └── bevy_internal v0.12.1
                └── bevy v0.12.1
windows v0.52.0
└── gilrs-core v0.5.10
    └── gilrs v0.10.4
        └── bevy_gilrs v0.12.1
            └── bevy_internal v0.12.1
                └── bevy v0.12.1

This is a pretty big issue for rust-analyzer users at least (and I assume not too nice for compilation speed either). Why? Well, these crates are absolutely massive, and due to how rust-analyzer works (for the time being, ideally it wouldn't), rust-analyzer currently loads every source file into memory at start up for speed (and unfortunately duplicates this for normalizing file endings). This wastes a ton of memory due to the windows crate being enormous in source code size (a whopping 1.5 - 1.6gb!), and this is without any other related computed information like early name resolution which could be pretty big for these crates as well!

Now this is not a problem for bevy itself, but certainly for the user experience of people working with the engine in rust-analyzer so I figured I should bring this up.

Additional information

https://github.com/rust-lang/rust-analyzer/issues/16301

rlidwka commented 6 months ago

cargo tree -d is a cool command, we should probably pay more attention to what it says

mockersf commented 6 months ago

it's known, Bevy CI used to fail on this... but not much we can do as the dependencies don't have all the same lifecycle.

it should "only" impact the build time and the bin size, not performance

Veykril commented 6 months ago

Well, feel free to close this. Just wanted to raise for awareness as r-a is kind of limited in what it can do here currently. I have a small idea that will get memory waste from this down by a third, gonna try implementing that next week, but that still leaves a lot of memory.

Veykril commented 6 months ago

Okay, https://github.com/rust-lang/rust-analyzer/pull/16307 will get rid of the extra in memory source file stores, so this can be closed if you don't think this is a problem for you to track. I would seriously recommend though trying to get rid of windows crate duplication as it is just a really damn massive crate in terms of source size. Someone checking out rust + bevy for the first time will download 700mbs of source files to their crates io index just for those 4 crates.

lnicola commented 6 months ago

N.b.: that gets rid of the extra copy, but we still store all the source code of the four crates in memory (as described above).

VirxEC commented 6 months ago

At the very least, windows v0.44.0 will be dropped when 0.13 lands and wgpu is updated to 0.18.

Vrixyz commented 6 months ago

I got curious so ran cargo bloat:

on my machine the example 2d_gizmos, windows ends up taking 0.1% of the file size, 107.7KiB on my machine.

Size in binary is not the main point of this issue but it's interesting nonetheless.

Details

cargo bloat -n 250 --crates --example 2d_gizmos Finished dev [unoptimized + debuginfo] target(s) in 0.53s Analyzing C:\Users\thier\Documents\cargo_target_dir\debug\examples\2d_gizmos.exe File .text Size Crate 7.4% 10.1% 5.4MiB wgpu 6.3% 8.5% 4.6MiB bevy_render 5.7% 7.7% 4.1MiB bevy_pbr 3.1% 4.2% 2.2MiB bevy_core_pipeline 2.7% 3.7% 2.0MiB bevy_ui 2.6% 3.6% 1.9MiB wgpu_hal 2.5% 3.5% 1.8MiB taffy 2.5% 3.4% 1.8MiB naga 2.0% 2.8% 1.5MiB bevy_gltf 1.9% 2.6% 1.4MiB bevy_asset 1.8% 2.4% 1.3MiB bevy_sprite 1.7% 2.3% 1.2MiB bevy_reflect 1.6% 2.2% 1.2MiB bevy_input 1.6% 2.2% 1.2MiB regex_automata 1.6% 2.1% 1.1MiB bevy_window 1.4% 1.9% 1.0MiB bevy_ecs 1.4% 1.9% 1.0MiB gltf_json 1.3% 1.7% 933.7KiB regex_syntax 1.3% 1.7% 929.1KiB bevy_audio 1.2% 1.6% 877.0KiB aho_corasick 1.1% 1.4% 786.3KiB bevy_winit 1.1% 1.4% 783.6KiB bevy_text 1.0% 1.3% 735.2KiB bevy_scene 1.0% 1.3% 705.5KiB naga_oil 0.9% 1.2% 667.6KiB std 0.9% 1.2% 665.1KiB bevy_animation 0.9% 1.2% 664.1KiB bevy_gizmos 0.8% 1.1% 617.8KiB wgpu_core 0.8% 1.1% 598.9KiB data_encoding 0.6% 0.9% 470.5KiB tracing_subscriber 0.5% 0.7% 394.4KiB bevy_transform 0.5% 0.7% 360.0KiB bevy_time 0.4% 0.6% 329.3KiB lewton 0.4% 0.6% 301.4KiB winit 0.4% 0.5% 291.3KiB ttf_parser 0.3% 0.4% 212.8KiB gilrs 0.3% 0.4% 203.7KiB rodio 0.3% 0.4% 198.3KiB image 0.3% 0.4% 196.2KiB gilrs_core 0.3% 0.3% 189.8KiB gltf 0.3% 0.3% 185.8KiB bevy_core 0.2% 0.3% 174.2KiB glow 0.2% 0.3% 170.6KiB ruzstd 0.2% 0.3% 164.1KiB accesskit_consumer 0.2% 0.3% 159.8KiB png 0.2% 0.3% 155.3KiB sysinfo 0.2% 0.3% 154.6KiB accesskit_windows 0.2% 0.3% 148.9KiB bevy_app 0.2% 0.3% 143.2KiB memchr 0.2% 0.2% 129.1KiB bevy_internal 0.2% 0.2% 126.4KiB ash 0.2% 0.2% 126.2KiB bevy_hierarchy 0.2% 0.2% 121.3KiB cpal 0.2% 0.2% 117.2KiB gpu_allocator 0.2% 0.2% 113.5KiB rustc_demangle 0.1% 0.2% 109.4KiB async_fs 0.1% 0.2% 107.7KiB windows 0.1% 0.2% 102.5KiB serde_json 0.1% 0.2% 92.4KiB bevy_gilrs 0.1% 0.2% 91.9KiB ron 0.1% 0.2% 85.0KiB wgpu_types 0.1% 0.2% 84.6KiB codespan_reporting 0.1% 0.1% 80.7KiB bevy_tasks 0.1% 0.1% 80.5KiB windows_core 0.1% 0.1% 66.7KiB tracing_core 0.1% 0.1% 65.7KiB ab_glyph 0.1% 0.1% 60.6KiB d3d12 0.1% 0.1% 59.9KiB fdeflate 0.1% 0.1% 57.8KiB bevy_log 0.1% 0.1% 57.6KiB backtrace 0.1% 0.1% 57.5KiB async_executor 0.1% 0.1% 56.2KiB accesskit 0.1% 0.1% 55.7KiB ogg 0.1% 0.1% 55.1KiB hassle_rs 0.1% 0.1% 53.3KiB hashbrown 0.1% 0.1% 49.8KiB glam 0.1% 0.1% 49.3KiB blake3 0.1% 0.1% 45.0KiB parking_lot 0.1% 0.1% 40.0KiB parking_lot_core 0.0% 0.1% 34.7KiB gpu_alloc 0.0% 0.1% 34.5KiB base64 0.0% 0.1% 34.1KiB blocking 0.0% 0.1% 29.6KiB simd_adler32 0.0% 0.1% 29.4KiB bevy_a11y 0.0% 0.1% 28.7KiB bevy_mikktspace 0.0% 0.1% 28.2KiB const_panic 0.0% 0.0% 27.4KiB event_listener 0.0% 0.0% 26.0KiB crossbeam_utils 0.0% 0.0% 25.0KiB widestring 0.0% 0.0% 25.0KiB tracing_log 0.0% 0.0% 24.6KiB owned_ttf_parser 0.0% 0.0% 22.2KiB bevy_diagnostic 0.0% 0.0% 22.1KiB async_lock 0.0% 0.0% 21.6KiB ab_glyph_rasterizer 0.0% 0.0% 21.3KiB uuid 0.0% 0.0% 21.0KiB guillotiere 0.0% 0.0% 19.2KiB ktx2 0.0% 0.0% 17.8KiB termcolor 0.0% 0.0% 17.4KiB thread_local 0.0% 0.0% 17.0KiB libloading 0.0% 0.0% 16.8KiB sharded_slab 0.0% 0.0% 15.1KiB nu_ansi_term 0.0% 0.0% 14.9KiB enum2$

JMS55 commented 5 months ago

We're currently down to 3 copies (2 outdated)

  1. One will be fixed by updating accesskit_winit https://github.com/bevyengine/bevy/pull/11466
  2. One of them needs rodio->cpal to update their windows dependency