Seeking suggestions for efficient rendering of large lists #962
Replies: 1 comment 2 replies
-
Hello @AlexKordic,
The screen height is a good "upper bound". You can access it with: ScreenInteractive::Active()->dimy() Assuming you know the "selected" element, and the children size is at least one row: Element MyMenu::Render() final {
if (!ActiveChild()) {
return text("No children???")
}
const int selected = ActiveChild()->Index();
const auto height = ScreenInteractive::Active()->dimy();
Elements out;
for(int i = std::max(selected - height, 0);
i < std::min(selected + height, children_.size());
i++) {
out.push_back(children_->Render())
}
return vbox(std::move(out));
} Note 1: If you are dealing with dom Note 2: This could be an optimization we might want to copy-paste into the What do you think? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am working on optimizing the rendering of a large error log (1000 items) in application. My current vertical container takes about 700ms to render, and I am exploring two potential solutions to improve performance:
Caching Approach:
Cache all created Elements between render calls.
However, this feels problematic as it duplicates the data in the UI layer, which conflicts with the principles of the model-view idiom.
Subset Rendering Approach:
Render only a subset of visible Elements (e.g., 55 visible items out of 1000 total).
This approach introduces challenges such as:
To tackle these challenges, I subclassed
ComponentBase
(similar toMenuBase
) so theRender()
method dynamically produces the subset ofElement
s for each cycle.To determine the available space (height), I subclassed
Node
(inspired byReflect
) and used the following sequence:Initially,
Menu::Render()
doesn't know the height, so it renders a preconfigured number of elements.Then
SetBox(Box box)
in the customNode
gets called, followed byRender(Screen& screen)
, where I calculate the height using:Since this calculated height isn't accounted for in the initial render, I trigger another render cycle using
screen.Post(Event::Custom);
. I’ve added safeguards to prevent infinite render loops.For the scroll bar, I created a custom element that takes the dataset's total size into account instead of just the rendered subset. This approach works, but I'm facing difficulties with elements that span multiple rows. My current calculations for such cases are still a work in progress.
At present, I render approximately height rows in the custom
Menu
, which often exceeds the available space. To handle this, I use the| yframe
decorator to center the content around the focused item. This has reduced the rendered subset to the visible height instead of rendering the entire dataset.Are there any better alternatives for efficiently handling such scenarios in FTXUI?
Any suggestions or insights would be greatly appreciated!
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions