bevyengine / bevyengine/bevy

Performance cost of `std::any::type_name` and `impl Bundle`

Open
#20,284 7 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Bug C-Performance I-Regression S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.16.1

## Relevant system information

cargo 1.88.0 (873a06493 2025-05-10)
Windows 11

## What's performing poorly?

I've been dealing with poor compile times on my main workspace project. I've been debugging it a bit and I believe the root cause was a lot of time spent in `compute_debuginfo_type_name`.

In my project, I use functions that return `impl Bundle` heavily, sometimes in a nested fashion:
```rust
fn make_bundle() -> impl Bundle {
/* ... */
}
```

With some profiling, I noticed that the compiler is spending an awful long time in `compute_debuginfo_type_name`:

Image

So I did some quick refactoring to reduce my usage of `impl Bundle`. This drastically reduced the time spent in `compute_debuginfo_type_name`.

Image

This dropped the compilation time of my crate to about half of what it used to be.

Thing is, I don't think this is my code calling `std::any::type_name` on these bundles. My assumption is that this is because of the debug print messages for `impl Bundle` types, but I'm not 100% sure.

Mainly opening this thread to discuss any potential optimizations.

Raw trace files:
Before: https://drive.google.com/file/d/1hx6l87tnrcgKoFbIselbbjWtAXlRGZgo/view?usp=drive_link
After: https://drive.google.com/file/d/1NmRejNCJISYwFoZb4f_v6-etdttyURy3/view?usp=drive_link

Contributor guide

Open the contributing guide

Research direction

Start with the linked raw trace files and the reported compute_debuginfo_type_name hotspot, then compare the traces before and after reducing nested impl Bundle usage. Investigate whether Bevy's impl Bundle-related debug output or std::any::type_name usage accounts for the compile-time cost. Done means identifying and validating a concrete optimization or documenting why the cost cannot be reduced.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.