js-performance-patterns

Applies JavaScript runtime performance patterns to hot paths, loops, and DOM operations.

1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/TierOne-Studio/spa-velocity --skill js-performance-patterns-tierone-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: js-performance-patterns
Source: https://github.com/TierOne-Studio/spa-velocity/tree/main/.ruler/skills/js-performance-patterns
Command: npx skills add https://github.com/TierOne-Studio/spa-velocity --skill js-performance-patterns-tierone-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? JavaScript code in hot paths—tight loops, high-frequency event handlers, and large dataset processing—often wastes CPU through linear lookups, layout thrashing, and redundant computation. This Skill provides concrete, framework-agnostic patterns to eliminate those bottlenecks. ## Core Features & Use Cases - Lookup Optimization: Replace O(n) array scans with Set and Map for O(1) lookups in large collections. - DOM Performance: Batch DOM reads and writes to prevent layout thrashing, and sync visual updates with requestAnimationFrame. - Computation Caching: Memoize expensive function results and hoist RegExp compilation out of loops. - Use Case: When profiling reveals a scroll handler dropping frames, apply the batched read/write and requestAnimationFrame patterns to restore smooth 60fps rendering. ## Quick Start Review my scroll event handler and data filtering code and apply the appropriate JavaScript performance patterns to the hot paths.

Frequently Asked Questions about js-performance-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize JavaScript loops processing large arrays?

Cache array length and nested property access outside the loop, and combine chained filter/map/reduce calls into a single pass to avoid intermediate arrays. These changes matter for arrays with 10,000+ items or code running at 60fps.

How to prevent layout thrashing when updating the DOM?

Batch all DOM reads first, then perform all writes, so the browser recalculates layout once instead of per element. For complex cases, defer writes with requestAnimationFrame or use a library like fastdom.

When should I use Set or Map instead of arrays in JavaScript?

Use Set or Map when performing repeated lookups against the same collection, since .has() and .get() are O(1) versus O(n) for .includes() or .find(). Map also outperforms plain objects when keys are added and removed dynamically.

Does requestAnimationFrame improve scroll handler performance?

Yes, wrapping visual updates in requestAnimationFrame syncs them with the browser's render cycle and prevents jank. Combine it with a ticking flag so updates run at most once per frame, and keep the scroll listener passive.

When should I avoid JavaScript micro-optimizations?

Avoid them in cold code paths where readability matters more than nanosecond gains. Fix algorithmic complexity first, such as reducing O(n^2) to O(n), and apply micro-patterns only after profiling identifies a genuine hot path.