Comfy-Org / Comfy-Org/ComfyUI_frontend
Optimize CurveEditor with typed arrays for better JIT performance
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Context
This optimization was identified during review of PR #8860.
**Related PR:** https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860
**Comment:** https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860#discussion_r2838861765
**Requested by:** @christian-byrne
## Optimization Details
Modern JS engines and JIT compilers can significantly improve performance when operations are easier to vectorize. Using typed arrays provides numeric stability and enables better compiler optimizations.
### Specific Changes Needed
In `src/components/curve/curveUtils.ts`, within the `createMonotoneInterpolator` function:
**Replace dynamic arrays for xs and ys:**
```ts
const xs = new Float64Array(n)
const ys = new Float64Array(n)
for (let i = 0; i < n; i++) {
xs[i] = sorted[i][0]
ys[i] = sorted[i][1]
}
```
**Replace dynamic arrays for deltas and slopes:**
```ts
const deltas = new Float64Array(n - 1)
const slopes = new Float64Array(n)
```
### Benefits
- Better JIT compiler vectorization
- Improved numeric stability
- Enhanced performance for curve interpolation operations
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9110-Optimize-CurveEditor-with-typed-arrays-for-better-JIT-performance-3106d73d3650815f8a51d7a441796e2b) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.