Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 4a678b22 authored by Yeabkal Wubshit's avatar Yeabkal Wubshit
Browse files

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
parent ab6ccbd7
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment