xonecas.io
556
Bn

bees-nest / files

bees-nest / .opencode / skills / vercel-react-best-practices / rules / js-cache-property-access.md

532 bytes
1---
2title: Cache Property Access in Loops
3impact: LOW-MEDIUM
4impactDescription: reduces lookups
5tags: javascript, loops, optimization, caching
6---
7
8## Cache Property Access in Loops
9
10Cache object property lookups in hot paths.
11
12**Incorrect (3 lookups × N iterations):**
13
14```typescript
15for (let i = 0; i < arr.length; i++) {
16  process(obj.config.settings.value)
17}
18```
19
20**Correct (1 lookup total):**
21
22```typescript
23const value = obj.config.settings.value
24const len = arr.length
25for (let i = 0; i < len; i++) {
26  process(value)
27}
28```