Skip to content

Commit 9c47ad8

Browse files
committed
Add array destructuring performance guideline to CLAUDE.md
1 parent 34df965 commit 9c47ad8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

CLAUDE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,12 @@ This is a TypeScript implementation of the Package URL (purl) specification for
323323
- **Array destructuring**: Use object notation for tuple access
324324
-CORRECT: `{ 0: key, 1: data }`
325325
-AVOID: `[key, data]`
326+
- **Array destructuring performance**: For `Object.entries()` loops, use object destructuring for better V8 performance
327+
-SLOWER: `for (const [key, value] of Object.entries(obj))`
328+
-FASTER: `for (const { 0: key, 1: value } of Object.entries(obj))`
329+
- **Rationale**: Array destructuring requires iterator protocol (per ECMAScript spec), while object destructuring directly accesses indexed properties
330+
- **Reference**: https://stackoverflow.com/a/66321410 (V8 developer explanation)
331+
- **Trade-off**: This is a microbenchmark optimization - prioritize readability unless profiling shows this is a bottleneck
326332
- **Array checks**: Use `!array.length` instead of `array.length === 0`
327333
- **Destructuring**: Sort properties alphabetically in const declarations
328334

0 commit comments

Comments
 (0)