Skip to content

Improve Animation Engine Performance & Frame Accuracy #47

@dclause

Description

@dclause

Motivation
Current animation engine is functional but lacks precision and scalability when attempting to control devices (like LEDs or servos) at higher frame rates (~20 FPS). Several areas have been identified that can be optimized to improve determinism, timing accuracy, and overall performance in a multi-track context with limited I/O bandwidth (e.g., serial comms).

Identified Optimization Areas

  1. Keyframe Search Complexity
    Currently O(N) per frame to find applicable keyframes across tracks. This is Acceptable for now due to low N, but may become a bottleneck.
    => Potential improvement: binary search on sorted keyframes, or prebuild flat timeline index.

  2. Box / Clone Overhead
    Heavy use of Box and .clone() on State objects.
    => Suggestion: Use &dyn OutputDevice when mutation not needed.
    => Consider moving to Rc or using Cow for cloned data.

  3. Time Drift / Inaccuracy at High FPS
    Observed 100ms keyframes blink between 110–130ms in real-world. The cuase seems to be the order of operations: time to compute + send + wait until next frame adds non-negligible delay.
    => Precompute frame output state, then delay until precise tick.
    => Use tokio::time::interval() to drive frame rate reliably.

  4. Generic Timing Model
    => Using a tokio interval() system, can be / should we do "step by step" animation ?
    => How about having a speed factor (speed: f32), Should it be modifiable on the fly ?

  5. Track Conflict Detection
    Should add_track() enforces no overlap of keyframes ? How to prevent forcing .unwrap() in most usages.
    => consider builder pattern or API that accumulates diagnostics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    PlanMeta issuecode qualityIssue is related to refactoring or improving code quality overall.feature requestNew feature or requestperformancePerformance improvement related issue

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions