Comfy-Org / Comfy-Org/ComfyUI_frontend
Optimize histogramToPath performance in curveUtils
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Performance Optimizations for histogramToPath
Requested by @christian-byrne in [PR #8860 review comment](https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860#discussion_r2838865130).
### Suggested Optimizations
The `histogramToPath` function in `src/components/curve/curveUtils.ts` has several opportunities for performance improvements:
1. **Use Array.join instead of string concatenation** - Building the SVG path string using an array and joining at the end is more efficient than repeated string concatenation in the loop.
2. **Replace toFixed with manual rounding** - Manual rounding (`Math.round(x * 10000) / 10000`) is faster than `toFixed(4)` in hot paths.
3. **Hoist step calculations and use accumulation** - Instead of computing `i * step` on each iteration, accumulate `x += step` to reduce multiplication operations.
See the [original comment](https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860#discussion_r2838865130) for detailed code examples.
### Context
- Related PR: #8860
- File: `src/components/curve/curveUtils.ts`
- Function: `histogramToPath`
---
_This issue was created as a follow-up to optimize the CurveEditor component introduced in #8860._
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9117-Optimize-histogramToPath-performance-in-curveUtils-3106d73d365081018234f081569b3399) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.