Skip to content

Reduce bsn! codegen / debug symbols by combining scene implementations#24124

Merged
cart merged 6 commits intobevyengine:mainfrom
cart:better-bsn-codegen
May 6, 2026
Merged

Reduce bsn! codegen / debug symbols by combining scene implementations#24124
cart merged 6 commits intobevyengine:mainfrom
cart:better-bsn-codegen

Conversation

@cart
Copy link
Copy Markdown
Member

@cart cart commented May 4, 2026

Objective

bsn! currently generates a lot of new types: one for each patch, which then get assembled into a single Scene impl by composing them in a tuple. This gives the compiler more work to do (types to verify, code to generate, etc). It also makes our debug symbols bigger / harder to read.

Solution

Combine bsn! entries, where possible, into a single SceneFunction<F> implementation of Scene, which does all of the "scene patch" logic internally. This significantly cuts down on codegen, and also makes the functional behavior of a bsn! block more clear when expanded.

@cart cart added this to the 0.19 milestone May 4, 2026
@cart cart added C-Performance A change motivated by improving speed, memory usage or compile times C-Code-Quality A section of code that is hard to understand or change A-Scenes Composing and serializing ECS objects labels May 4, 2026
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label May 4, 2026
@cart cart closed this May 5, 2026
@cart cart reopened this May 5, 2026
@cart cart force-pushed the better-bsn-codegen branch from ab68063 to 427c4f1 Compare May 5, 2026 00:24
@alice-i-cecile alice-i-cecile self-requested a review May 5, 2026 05:24
Comment thread crates/bevy_scene/macros/src/bsn/codegen.rs Outdated
Copy link
Copy Markdown
Contributor

@laundmo laundmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially i thought SceneFunction would cause issues with asset dependencies, but after asking cart who said it can't contain any code that adds dependencies and testing the case i was thinking of locally, it seems to work as expected.

very nice!

@cart cart enabled auto-merge May 6, 2026 19:59
@cart cart added this pull request to the merge queue May 6, 2026
Merged via the queue into bevyengine:main with commit 6c0eb84 May 6, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Code-Quality A section of code that is hard to understand or change C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants