Skip to content

PyModel/pythinker-code / .agents/skills/ts-performance-rules

ts-performance-rules

Verified

TypeScript and JavaScript performance and code-quality rules, usable in any framework. Use when writing, reviewing, or refactoring hot paths, data-structure choices, async flows, or bundle-size-sensitive code. Triggers include "optimize this function", "too slow", "reduce allocations", "bundle size", "lazy load", "speed up imports", or general code review of utilities and services.

TypeScript performance rules

A rule catalog for TypeScript/JavaScript code in this repository. Rules are framework-neutral: they apply to the CLI, the agent engines, the gateway, and the web apps. Each rule file states its impact band, an incorrect/correct pair, and the reasoning.

Derived from Vercel's react-best-practices rule catalog (MIT); the React-component-specific rules are intentionally not part of this skill.

Rule index

Plain JavaScript efficiency (js-*.md)

RuleApplies when
js-early-exitLoops keep scanning after the answer is known
js-length-check-firstCheap guards can precede expensive calls
js-set-map-lookupsArrays are scanned inside loops for membership
js-index-mapsRepeated lookups rebuild the same index
js-flatmap-filterfilter().map() (or the reverse) makes two passes
js-combine-iterationsMultiple loops over the same array can share one pass
js-hoist-regexpRegex literals or constructions sit inside hot loops
js-min-max-loopMath.min(...bigArray) style spreads blow the stack or re-scan
js-cache-function-resultsPure functions recompute the same inputs
js-cache-property-accessDeep property chains are read repeatedly in loops
js-cache-storagelocalStorage/sessionStorage reads sit in hot paths
js-batch-dom-cssDOM style reads/writes alternate and force layout thrash
js-request-idle-callbackNon-urgent work blocks interaction
js-tosorted-immutable.sort() mutates arrays that callers own

Async structure (async-*.md)

RuleApplies when
async-cheap-condition-before-awaitA cheap guard sits after an expensive await
async-defer-awaitIndependent awaits run serially for no reason
async-parallelIndependent promises could run through Promise.all
async-dependenciesA chain of awaits hides which steps truly depend on each other

Bundle size (bundle-*.md)

RuleApplies when
bundle-barrel-importsImports pull whole barrel files for one symbol
bundle-conditionalLarge dependencies load for features that are rarely enabled
bundle-defer-third-partyThird-party SDKs load eagerly at startup
bundle-dynamic-importsRare code paths could be import() splits
bundle-preloadKnown-next navigations could preload their chunks
bundle-analyzable-pathsDynamic import paths are built in ways bundlers cannot trace

How to apply

  1. Pick rules by the code's actual shape, not by keyword match alone; the impact band in each rule's frontmatter says how much it typically matters.
  2. Apply the smallest change that satisfies the rule; do not restructure working code beyond the rule's scope.
  3. For repository-specific constraints, the nearest AGENTS.md and the package's own tests win over these general rules.
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 318kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 318kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 318kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 318kUpdated Claude CodeCodexVerifiedInstall