Skip to content

Commit

Permalink
Assess and remove unnecessary usage of Float32Array (#6243)
Browse files Browse the repository at this point in the history
## Summary

This PR removes a 4-year-old TODO in the `Bezier` library, keeping
`Arrays` and removing mentions of `Float32Arrays`.

This is due to `Float32Arrays` having a very specific `WebGL` use case,
and generally being slower than regular `Arrays`, especially when
they're dynamically re-allocated over and over again as it is the case
in the `Bezier` library.

Live speed demo: [link](https://jsperf.app/float32array-slowness-test/2)
Live demo results:

![image](https://github.com/software-mansion/react-native-reanimated/assets/74246391/7551de0b-b9ab-439e-9853-fee0178253af)

## Test plan

not-applicable

## Notes

Using `Float32Array` here has no effect on precision, and no measurable
speed improvement/degradation was noted on the
production-like-conditions tests that I did.
  • Loading branch information
latekvo authored Jul 9, 2024
1 parent b495f73 commit 77644ca
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/react-native-reanimated/src/Bezier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,9 @@ export function Bezier(
return LinearEasing;
}

// FIXME: Float32Array is not available in Hermes right now
//
// var float32ArraySupported = typeof Float32Array === 'function';
// const sampleValues = float32ArraySupported
// ? new Float32Array(kSplineTableSize)
// : new Array(kSplineTableSize);

// Precompute samples table
const sampleValues = new Array(kSplineTableSize);

// Precompute samples table
for (let i = 0; i < kSplineTableSize; ++i) {
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
}
Expand Down

0 comments on commit 77644ca

Please sign in to comment.