-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deep nesting results in poor performance #71
Comments
This is not expected. It should scale much much better than this. Probably something to do with a specific calculation which means it's very tied to the specific tree you are passing in. Could you write a benchmark and submit it as a pull request (extending the current benchmark suite) so that we could have a look? |
I have met the same issue. The following code can show it: use std::time::SystemTime;
use stretch::geometry::Size;
use stretch::style::*;
fn main() -> Result<(), stretch::Error> {
let mut stretch = stretch::node::Stretch::new();
let node = stretch.new_node(
Style { size: Size { width: Dimension::Points(50.), height: Dimension::Points(50.) }, ..Default::default() },
vec![],
)?;
let mut child = stretch.new_node(Style::default(), vec![])?;
stretch.set_children(node, vec![child]).unwrap();
for i in 0..20 {
let new_child = stretch.new_node(Style::default(), vec![])?;
stretch.set_children(child, vec![new_child]).unwrap();
child = new_child;
let now = SystemTime::now();
stretch.compute_layout(node, Size::undefined())?;
println!("elapsed: {} nodes -> {:?}", i + 3, now.elapsed());
}
Ok(())
} in debug mode:
and in release:
adding one node as a leaf doubles the |
I'm using stretch to lay out a tree-like structure. With 63 nodes and a maximum depth of 16,
compute_layout
takes about 5 seconds to complete. Profiling illustrates that compute time increases exponentially with depth, and thatcompute_internal
is called over 50k times for my structure of 63 nodes.Is this sort of performance expected? Is nesting this deeply just an entirely unexpected thing to be doing with stretch? Are there constraints I could be putting in place to elide some of this recursion?
The text was updated successfully, but these errors were encountered: