Replace ChildBufferCache with a simpler stack allocator. - #25593
Conversation
Instead of the vec of vecs, use a single vec stack allocator.
PPakalns
left a comment
There was a problem hiding this comment.
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 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. |
Not sure, the ordering needs to be stable and sorting in reverse might mess it up? Eliminating the recursion might be good though, I guess the stack could overflow if someone had a crazy deep tree for some reason. |
Yes, it will probably mess it up. In that case additional reverse call would be needed. |
Objective
Replace the
ChildBufferCacheused inui_stack_systemwith a simpler stack allocator.Solution
Instead of the vec of vecs, use a single vec stack allocator.
Testing
The
stackmodule's tests all still pass.Showcase