Switch the runtime data structure used to store segments in the timeline #9
Labels
performance
This ticket is about performance optimization
timeline
Issues related to the WebGL timeline (@aitube/timeline)
Context
Currently segments are stored as
Array<TimelineSegment>
, with various temporary data structures to handle time splicing (seeBufferedSegments
oractiveSegments
in the codebase)Goal
I would like to simplify the code and improve performance by reducing the number of
.find()
and.filter()
operations neededLimitations / 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):
I was also thinking of maybe using a sorted B Tree:
https://www.npmjs.com/package/sorted-btree#features
Acceptance criteria
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)
The text was updated successfully, but these errors were encountered: