Skip to content

optilintFind and fix slow JavaScript and TypeScript

A type-aware linter that only cares about speed. Every fix says what it guarantees, and every fix is benchmarked on V8 and JavaScriptCore.

optilint
$ npx @optilint/cli srcOther ways to install →
summary.ts
  4:41   high    spread-in-accumulator   Spreading `acc` copies the accumulator on every step (O(n²)); mutate it instead. typed
  5:37   high    lookup-in-loop          `.find()` scans the array on every iteration (O(n·m)); build a Map keyed by what you match on once outside the loop.
  6:22   medium  filter-first            `.filter(...)[0]` scans the whole array; use `.find(...)`. assumed
  7:37   medium  regex-to-string-method  This regex matches plain text; a string method is faster. typed
  8:3    high    sequential-await        2 independent awaits run one after another; start them together with `Promise.all`. assumed
  10:68  low     date-now                Allocates a Date just to read the time; use `Date.now()`. exact

✖ 6 findings (3 high, 2 medium, 1 low) · 3 fixable with --fix, 2 more with --tier assumed / --obscure

Real output of optilint 0.0.5, regenerated on every build.

54rules with stable names27rules that --fix can rewrite24fixes benchmarked on 2 engines3fix tiers, so you know what changed

Fixes that say what they guarantee

A rewrite is only worth applying if it keeps your program correct. Every fix carries a tier, and --fix applies the first two by default.

exact

Same behaviour for every input.

new Date().getTime() → Date.now()

typed

Same behaviour for every input the types allow. The TypeScript checker proves the receiver is an array, a string, a Map.

xs.filter(f).length > 0 → xs.some(f)

assumed

Correct when the stated assumption holds, such as "these awaits are independent". --fix leaves them out unless you ask.

await a(); await b(); → Promise.all

Measured, not guessed

Each fix is benchmarked before and after on Node (V8) and Bun (JavaScriptCore), at every compiler tier from the interpreter up. A fix that measured slower is retired, and rules over your maxSlowdown don't run.

How much faster each fix runs on V8 and JavaScriptCore, worst to best case

How the benchmarks work →

Where you already work

Run it on your code

No config needed: run it in the project root and it lints what git lists, with your tsconfig.

Released under the MIT License.