Comfy-Org / Comfy-Org/ComfyUI_frontend
Optimize sorting performance in useCurveEditor composable
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 699
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 490
Description
## Problem
Currently, `useCurveEditor` performs sorting in two places:
1. **`sortedPoints` computed property** (line 15-19): Creates a sorted copy for rendering and interpolation
2. **`sortByX` function** (line 89-91): Sorts again in `endDrag` when deleting points
This redundant sorting impacts performance and could lead to index stability issues during drag operations.
## Proposed Solutions
### Option 1: Unsorted storage with sorted view
- Keep `modelValue` in insertion/selection order (stable indices)
- Use `sortedPoints` computed property for rendering/interpolation only
- Remove sorting from `endDrag` (or only sort if sorted model storage is required)
**Benefits:**
- Stable indices during drag operations
- Avoids potential UX bugs from reordering
- Eliminates extra sort operations
### Option 2: Always-sorted storage
- Enforce invariant: `modelValue.value` is always sorted by x-coordinate
- Remove sorting from `sortedPoints` (becomes identity operation)
- Update dragging logic to handle dynamic indices
**Benefits:**
- Single source of truth
- Simpler mental model (always sorted)
- Eliminates redundant sorting in computed property
## References
- PR: https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860
- Comment: https://github.com/Comfy-Org/ComfyUI_frontend/pull/8860#discussion_r2838889727
- File: `src/composables/useCurveEditor.ts`
- Requested by: @christian-byrne
┆Issue is synchronized with this [Notion page](https://www.notion.so/Issue-9115-Optimize-sorting-performance-in-useCurveEditor-composable-3106d73d365081e794b3f260fbca2ff6) by [Unito](https://www.unito.io)
Contributor guide
Assessment
This issue has not been assessed yet.