Avoid Temporary Memory Allocation in Impulse Velocity Calculation
During calculating impulse velocity, we used to create arrays to store
the data ponits that are within the HORIZON, and then pass those arrays
(1 for position and one for time) to a separate static function to
calculate velocity. This means that we have to do extra space allocation
(~O(n)), plus process most/all data points twice - once during
collecting the valid data points, and once during using their data to
get velocity.
This implementation avoids new array allocation by using a single linear
processing to both get the valid data points (i.e. the ones within
HORIZON from the latest data point), and to get the velocity. This
approach also has the side-effect benefit of avoiding consideration of
any old data-point on future calls on "computeCurrentVelocity", as we
will effectively mark a data point permanently "invalid" if it fails to
fall within the HORIZON at any point.
Trace-based analysis indicates that this approach improves the
`getVelocity` method by ~20% in time.
Bug: 267211645
Test: unit tests unaffected
Change-Id: Ie7671194476cd17131d79c06b5bc1440a958d384
2 files changed