Skip to content

easer/ecalc.js _cNN() function structure improvements, scripted generation of code #4

@sidewayss

Description

@sidewayss

The current (initial) design is the simplest of several, and the worst performing. It has 15 of the core animation-time calc functions, named in the format _cNN(), and a noop() that fills the data array. Those 15 calcs call one of 4 functions that perform the basic math:

  1. f() for factor aka multiplier: *
  2. a() for addend, a number added to the value with "+", generally equivalent to the animation's start value
  3. Math.max() is already a function
  4. Math.min() is already a function

So single property value/argument can run up to 4 calc functions, each running one of the 4 math functions, for 8 function calls total.

Also note: forEach loops are notoriously slower than other types of iterators. The calc functions rely on forEach to take advantage of how they skip empty array slots, and to simplify the code.

The best performing design would bloat the code and probably require being generated by script (via AI?) because it's too tedious for a human, certainly for me. The ideal would be for only 1 function to run each time, versus the current 8. That's a whole lot of permutations.

There is at least one intermediate step, which involves encapsulating all the different dimensionality into the permutations of the 4 math functions. The result would be 11 functions, each handling all the permutations of dimensionality:

#f()
#a()
#m()
#fa()
#fm()
#am()
#mm()
#fam()
#fmm()
#amm()
#famm()

Before embarking on any of that, baselines must be set and tests must be run to determine if it's worth it. My perspective is that, ideally, this code would be highly optimized so that the biggest, most complex animations could run as smoothly as possible. But this is a substantial amount of coding and even more testing, so I'm not expecting it any time soon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceperformance enhancment

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions