mirror of https://github.com/sveltejs/svelte
perf: avoid O(n²) name scanning in scope generate/unique (#17844)
## Summary `Scope.generate()` and `ScopeRoot.unique()` search for available names by iterating from suffix `_1` upward. When the same preferred name is generated many times (e.g. `text` is generated 482 times in a large component), the Nth call re-scans all N-1 already-taken names — O(n²) total work. This adds a `#name_counters` Map to `ScopeRoot` that tracks the next suffix to try per name, so each call resumes from where the last one left off. Generated names are identical to before. ## Benchmark (interleaved, best-of-3 rounds) | Component | Min | Median | |---|---|---| | Realistic (~80 lines) | ~1% | ~7% | | Medium (316 lines) | ~1% | ~5% | | Large (642 lines) | ~7% | ~2% | | XLarge (1302 lines) | **~11%** | **~10%** | ## Test plan - [x] All snapshot tests pass (name generation unchanged) - [x] All validator, compiler-error, runtime-runes, runtime-legacy tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>pull/17842/head
parent
2f12b60701
commit
32111f9e84
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
perf: avoid O(n²) name scanning in scope `generate` and `unique`
|
||||
Loading…
Reference in new issue