Skip to content
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

perf: take Tree::new items by reference #32

Merged
merged 5 commits into from
May 16, 2024

Conversation

sandercm
Copy link
Contributor

Currently you are forced to copy the items into the tree. With this change you can avoid this overhead. It works for my use case but if I missed something please let me know.

@EdJoPaTo
Copy link
Owner

The idea of a TreeItem is to only keep a reference to its content rather than moving the full content into the item. That's why the TreeItem has a reference in there: TreeItem<'a, Identifier>. It's a reference to the original content. Text<'a> does the same, keeping the reference to the original content.

As the TreeItem should be rather small this way it shouldn't improve on being a reference again.

I think benchmarks would be interesting to find out whether this is a bottleneck or not.

@sandercm
Copy link
Contributor Author

My usecase is quite extreme the json reply is ~13MB so even just copying that many references felt quite slow. How would I go about benchmarking this?

@EdJoPaTo EdJoPaTo force-pushed the main branch 7 times, most recently from 540e84b to 9fe712f Compare May 1, 2024 16:26
@EdJoPaTo
Copy link
Owner

EdJoPaTo commented May 1, 2024

I hope something like this is not necessary, and I prefer improving the performance rather than using something like this. (More detailed answer in the related issue). So I would close this for now. Or do you have other thoughts here?

@sandercm
Copy link
Contributor Author

sandercm commented May 2, 2024

I agree that improving the performance of TreeItem seems like a good idea. But I'm not sure why you don't like this approach of passing the items by reference. Even if the performance overhead is minimal when you are dealing with large json objects, you basically have deeply recursive datastructres that require a full traversal of the vec to copy it even if the indiviual copies are super fast you still end up with O(n) operations vs O(1) if you pass a reference. For smaller json objects it's basically unnoticable but for larger json objects the performance gain is huge.

In my case my fps went x15-20 simply making Tree take a reference (for json ~11MB), so I would be interested in hearing why you'd prefer to not use them?

Copy link
Owner

@EdJoPaTo EdJoPaTo left a comment

Choose a reason for hiding this comment

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

I am thinking about a release in between the current v0.19.0 and the upcoming TreeData trait changes (#34). The TreeData allows for a lot more flexibility and is also taken by reference. It improves performance by a different approach and includes an example for JSON, which is way more performant then due to not generating items that aren't rendered.

To reduce the friction a release in between might be helpful and given that the TreeData takes a reference it might be a good idea to include this.

src/lib.rs Outdated Show resolved Hide resolved
@EdJoPaTo EdJoPaTo changed the title don't force copy of items into tree perf: take Tree::new items by reference May 15, 2024
@EdJoPaTo EdJoPaTo linked an issue May 15, 2024 that may be closed by this pull request
@EdJoPaTo EdJoPaTo merged commit b07b537 into EdJoPaTo:main May 16, 2024
29 checks passed
@sandercm
Copy link
Contributor Author

Hi, I haven't had time to continue working on my side projects until now but these changes are great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change items to reference
2 participants