Install this skill
npx skills add vercel-labs/agent-skillsWorks across Claude Code, Cursor, Codex, Copilot & Antigravity
Accessing nested object properties inside a loop forces the JavaScript engine to traverse the object tree repeatedly during every iteration. This redundant work consumes CPU cycles unnecessarily, especially when processing large arrays or datasets. By extracting the target value or property path into a variable before initiating the loop, you shift the lookup overhead outside the block execution context. This pattern ensures that the engine retrieves the value exactly once, reducing memory latency and execution time. This optimization is particularly effective in compute-intensive routines, such as data normalization, high-frequency DOM manipulation, or real-time calculations. By stabilizing the access path, you minimize the risk of expensive prototype chain lookups or repeated getter invocations that otherwise accumulate over thousands of iterations.
When to Use This Skill
- •Processing large datasets from APIs or JSON files
- •Updating object properties across extensive arrays in visualization tools
- •Performing batch calculations on nested configuration settings
- •Iterating through heavy data structures inside request handlers
How to Invoke This Skill
Example prompts that trigger this skill in Claude Code, Cursor, or Antigravity:
- “optimize this loop for performance
- “speed up property access inside this for-loop
- “reduce overhead of nested lookups in iteration
- “refactor code to cache object properties before loop
- “make this loop run faster by removing redundant lookups
What this skill does
- •Reduces property lookup frequency within iterative blocks
- •Minimizes CPU overhead caused by redundant object traversals
- •Optimizes array length access to prevent repeated property checks
- •Simplifies variable scope for improved read performance
- •Accelerates execution speed in tight, compute-heavy loops
When not to use it
- ✕When the array length or object values change during the loop
- ✕In scenarios where the performance bottleneck is network I/O, not CPU usage
- ✕When code readability suffers from over-caching simple, non-nested variables
Example workflow
- Identify a loop containing repeated property access like obj.a.b.c
- Extract the value or the nested object into a constant before the loop starts
- Cache the length of the array in a separate variable if it is static
- Replace the inside-loop property calls with the extracted constant
- Verify the output remains identical through unit tests
Pitfalls & limitations
- !Caching a value that should be dynamic if the loop logic alters the object
- !Over-optimizing loops that execute too few times to show a measurable speed difference
- !Obscuring code intent by creating too many temporary variables
FAQ
How it compares
Unlike manual optimization which requires constant vigilance, this skill enforces a structured pattern that minimizes lookup overhead automatically across your codebase.
📄 Full skill instructions — original source: vercel-labs/agent-skills
Cache object property lookups in hot paths.
**Incorrect (3 lookups × N iterations):**
for (let i = 0; i < arr.length; i++) {
process(obj.config.settings.value)
}**Correct (1 lookup total):**
const value = obj.config.settings.value
const len = arr.length
for (let i = 0; i < len; i++) {
process(value)
}How to Use This Skill Unit
Option A: Project-Specific (Recommended)
- Click "Download" above
- In your project, create the directory:
.agent/skills/js-cache-property-access/ - Save the file as
SKILL.md - The agent will automatically discover the skill based on its description.
Option B: Global Installation (All Agents)
Save the file to these locations to make it available across all projects:
- Claude Code:
~/.claude/skills/vercel-labs/agent-skills/js-cache-property-access/SKILL.md - Cursor:
~/.cursor/skills/vercel-labs/agent-skills/js-cache-property-access/SKILL.md - Antigravity:
~/.gemini/antigravity/skills/vercel-labs/agent-skills/js-cache-property-access/SKILL.md
🚀 Install with CLI:npx skills add vercel-labs/agent-skills