Skip to content

Performance cost of std::any::type_name and impl Bundle #20284

@Zeenobit

Description

@Zeenobit

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorC-PerformanceA change motivated by improving speed, memory usage or compile timesP-RegressionFunctionality that used to work but no longer does. Add a test for this!S-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions