Skip to content

Replace ChildBufferCache with a simpler stack allocator. - #25593

Open
ickshonpe wants to merge 2 commits into
bevyengine:mainfrom
ickshonpe:uistack-stack
Open

Replace ChildBufferCache with a simpler stack allocator.#25593
ickshonpe wants to merge 2 commits into
bevyengine:mainfrom
ickshonpe:uistack-stack

Conversation

@ickshonpe

Copy link
Copy Markdown
Contributor

Objective

Replace the ChildBufferCache used in ui_stack_system with a simpler stack allocator.

Solution

Instead of the vec of vecs, use a single vec stack allocator.

Testing

The stack module's tests all still pass.


Showcase

cargo run --example many_buttons --release --features="trace_tracy"
uistack

Instead of the vec of vecs, use a single vec stack allocator.
@ickshonpe ickshonpe added C-Performance A change motivated by improving speed, memory usage or compile times A-UI Graphical user interfaces, styles, layouts, and widgets D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 28, 2026
@github-project-automation github-project-automation Bot moved this to Needs SME Triage in UI Aug 28, 2026
@ickshonpe ickshonpe added the C-Code-Quality A section of code that is hard to understand or change label Aug 28, 2026

@PPakalns PPakalns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Using cnt, pop(), sort_by_key Reverse in some special cases could use even less memory, but probably in average case is just more complex code.

LGTM.

@PPakalns

PPakalns commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Using cnt, pop(), sort_by_key Reverse in some special cases could use even less memory, but probably in average case is just more complex code.

LGTM.

Just an optional idea:

One more optimization to avoid storing start, end on stack.

This function can be implemented as one while loop which at the start stores initial node_entity in child_buffer and then uses while let Some((entity, _)) = child_buffer.pop() to process nodes. When childrens are added, we use sort_by_key with Reverse wrapper helper type.

This would reduce amount of data stored on stack during recursion. But additional profiling is needed, maybe compiler already does some optimizations.

Recursive implementation of course is easier to understand than loop one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-UI Graphical user interfaces, styles, layouts, and widgets 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 D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

2 participants