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

feat: Improve performance of stack function #1281

Merged
merged 3 commits into from
Nov 6, 2021

Conversation

YoshiWalsh
Copy link
Contributor

@YoshiWalsh YoshiWalsh commented Nov 5, 2021

fixes #1233

Well this was a fun challenge. This PR improves the performance of the stack, substack, and stackSubgroups functions. It also refactors them so that they all use a single common function.

I tested this against a ~1,600 item dataset. Before the change, stacking took 4.6 seconds. After the change it takes 84 milliseconds.

I think the new algorithm is O(n log n) for the best case (order of items matches chronological order) and O(n^2) for the worst case (order of items is the exact inverse of chronological order). I believe the previous stacking algorithm was actually O(n^2 log n), and not the O(n^2) mentioned in yotamberk/timeline-plus#26. But I'm not a computer scientist, so someone else would have to confirm this.

I have tested this using the "subgroups" example and it appears to maintain the same stacking behaviour. I've also tested it with a large dataset in my employer's application and it looks identical there too. But I realise that this isn't exactly extensive testing, so please let me know if there's anything I missed.

Joshua Walsh added 3 commits November 5, 2021 13:29
This one only works if the items are sorted by their start time. So unfortunately it doesn't play nice with custom ordering.
Now the stacking algorithm respects order correctly, while still making a significant improvement to performance.
@yotamberk yotamberk self-assigned this Nov 6, 2021
@yotamberk
Copy link
Member

Nice work! I'll check this PR today and get it in ASAP

Copy link
Member

@yotamberk yotamberk left a comment

Choose a reason for hiding this comment

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

All the tests I checked seemed to pass.
Nice work!

@yotamberk yotamberk changed the title Improve performance of stack function feat: Improve performance of stack function Nov 6, 2021
@yotamberk yotamberk merged commit 171cdb4 into visjs:master Nov 6, 2021
@vis-bot
Copy link
Collaborator

vis-bot commented Nov 6, 2021

🎉 This PR is included in version 7.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

Slow performance in stack function
3 participants