Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply 62 React and Next.js performance optimization rules from Vercel Engineering
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/js-set-map-lookups.md
1---2title: Use Set/Map for O(1) Lookups3impact: LOW-MEDIUM4impactDescription: O(n) to O(1)5tags: javascript, set, map, data-structures, performance6---78## Use Set/Map for O(1) Lookups910Convert arrays to Set/Map for repeated membership checks.1112**Incorrect (O(n) per check):**1314```typescript15const allowedIds = ['a', 'b', 'c', ...]16items.filter(item => allowedIds.includes(item.id))17```1819**Correct (O(1) per check):**2021```typescript22const allowedIds = new Set(['a', 'b', 'c', ...])23items.filter(item => allowedIds.has(item.id))24```25