Skip to content

Commit ee5957f

Browse files
committed
Add array destructuring performance guideline to CLAUDE.md
1 parent 9a8113e commit ee5957f

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
@@ -245,6 +245,12 @@ This is the Socket SDK for JavaScript/TypeScript, providing programmatic access
245245
- **Array destructuring**: Use object notation for tuple access when appropriate
246246
- ✅ CORRECT: `{ 0: key, 1: data }`
247247
- ❌ AVOID: `[key, data]`
248+
- **Array destructuring performance**: For `Object.entries()` loops, use object destructuring for better V8 performance
249+
- ❌ SLOWER: `for (const [key, value] of Object.entries(obj))`
250+
- ✅ FASTER: `for (const { 0: key, 1: value } of Object.entries(obj))`
251+
- **Rationale**: Array destructuring requires iterator protocol (per ECMAScript spec), while object destructuring directly accesses indexed properties
252+
- **Reference**: https://stackoverflow.com/a/66321410 (V8 developer explanation)
253+
- **Trade-off**: This is a microbenchmark optimization - prioritize readability unless profiling shows this is a bottleneck
248254
- **Array checks**: Use `!array.length` instead of `array.length === 0`
249255
- **Destructuring**: Sort properties alphabetically in const declarations
250256

0 commit comments

Comments
 (0)