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

Switch the runtime data structure used to store segments in the timeline #9

Open
jbilcke-hf opened this issue Jul 7, 2024 · 0 comments
Labels
performance This ticket is about performance optimization timeline Issues related to the WebGL timeline (@aitube/timeline)

Comments

@jbilcke-hf
Copy link
Owner

Context

Currently segments are stored as Array<TimelineSegment>, with various temporary data structures to handle time splicing (see BufferedSegments or activeSegments in the codebase)

Goal

I would like to simplify the code and improve performance by reducing the number of .find() and .filter() operations needed

Limitations / things to checks

  • Each data structure has benefits and drawbacks: we probably should run benchmarks to really check if there are performance improvements by switching the data structure (and where the bottlenecks are)

  • I do not exclude the possibility to use multiple data structures (a bit like an index for a database), but this increases complexity (do we sync on each little change, or do we use cache invalidation strategies etc)

  • This is a deep, core change: we should probably add unit tests firsts

How to implement

Our problem can be represented by a Segment Tree:

https://en.wikipedia.org/wiki/Segment_tree

although (to quote wikipedia):

The segment tree is less efficient than the interval tree for range queries in one dimension, due to its higher storage requirement: O(n log n) against the O(n) of the interval tree.

I was also thinking of maybe using a sorted B Tree:
https://www.npmjs.com/package/sorted-btree#features

Acceptance criteria

  • the performance gain should be perceptible
  • this should also add benchmark tests to compare performance

Existing features of the app should still work as usual (the problem is that right now, we don't have automated tests to verify this)

@jbilcke-hf jbilcke-hf added performance This ticket is about performance optimization to refine This issue cannot be taken just yet, it needs spec refinement timeline Issues related to the WebGL timeline (@aitube/timeline) and removed to refine This issue cannot be taken just yet, it needs spec refinement labels Jul 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance This ticket is about performance optimization timeline Issues related to the WebGL timeline (@aitube/timeline)
Projects
None yet
Development

No branches or pull requests

1 participant