Skip to content

Rule reference ​

Generated from the rule definitions. Speedups are before ÷ after time of the fix, worst and best over every compiler tier and input size, measured 2026-11-19 on Node v26.13.1 and Bun 1.4.4. optilint --explain <rule> prints the same text.

accumulate ​

spread-in-accumulator ​

xs.reduce((acc, x) => ({ ...acc, [k]: v }), {}) → mutate acc

Spreading the accumulator copies everything collected so far on every step, which makes reduce O(n²). The initial value is a fresh literal, so mutating it is invisible to callers.

high impact. Fixes: typed, assumed. Measured speedup: V8 1.4×–32×, JavaScriptCore 1.31×–15×.

accumulate-by-copy-in-loop ​

xs = [...xs, x] / xs = xs.concat(x) / o = {...o, k: v} inside a loop

Rebuilding the collection on each iteration copies everything gathered so far: O(n²) time and garbage. Push or assign in place.

high impact. Fixes: assumed. Measured speedup: V8 1.3×–21×, JavaScriptCore 3.92×–26×.

lookup ​

lookup-in-loop ​

Linear search (includes/indexOf/find/some) inside a loop

A linear search inside a loop makes the whole thing O(n·m). Build a Set or Map once before the loop and each lookup becomes O(1).

high impact. Report only.

array-literal-lookup ​

['a', 'b'].includes(x) inside a function → x === 'a' || x === 'b' or a hoisted Set

The array literal is rebuilt on every call and then searched linearly. A few comparisons need no allocation; for longer lists a module-level Set gives O(1) lookups.

medium impact. Fixes: exact. Measured speedup: V8 1.2×–4.35×, JavaScriptCore 1.18×–5.23×.

quadratic-array-mutation ​

shift/unshift/splice inside a loop

These move every following element. Inside a loop over the same data that is O(n²); a head index, a reverse, or a single compaction pass is O(n).

medium impact. Report only.

async ​

await-in-loop ​

await inside a loop body, or a promise chain built with reduce

Each iteration waits for the previous one, so total time is the sum of all latencies. If iterations are independent, start them all and await Promise.all(...) (or batch them to bound concurrency). Loops that poll, retry, pace themselves, stop early, carry a value to the next iteration, or drive one browser page, editor or terminal are left alone.

high impact. Report only.

sequential-await ​

Back-to-back independent awaits → Promise.all

const a = await f(); const b = await g(); waits for f before starting g, even though g never reads a. Promise.all overlaps them. (Unsafe: g now starts before f settles, and a rejection in f no longer prevents g from running.)

high impact. Fixes: assumed.

arrays ​

filter-first ​

xs.filter(f)[0] → xs.find(f)

filter visits every element and allocates a new array; find stops at the first match and allocates nothing.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.08×–1.37×, JavaScriptCore 1.17×–1.82×.

filter-length-to-some ​

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

Counting matches allocates an array and visits every element; some() short-circuits on the first match.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.01×–1.22×, JavaScriptCore 0.94×–1.23×.

map-flat-to-flatmap ​

xs.map(f).flat() → xs.flatMap(f)

flatMap does one pass and skips the intermediate array.

low impact. Fixes: typed, assumed. Measured speedup: V8 0.94×–1.18×, JavaScriptCore 0.32×–2.08×.

unused-map ​

xs.map(f); with the result ignored → xs.forEach(f)

map allocates and fills a result array that nobody reads.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.04×–2.14×, JavaScriptCore 1.07×–1.28×.

redundant-array-copy ​

[...xs].map(f) → xs.map(f) for non-mutating methods

Copying an array before a method that does not mutate it costs an O(n) allocation for nothing.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.04×–1.53×, JavaScriptCore 1.03×–1.42×.

chained-array-methods ​

xs.filter(f).map(g) chains allocate an array per step

Each map/filter step allocates a full intermediate array and walks it again. One loop (or one reduce) does it in a single pass.

medium impact. Report only.

sort-for-extremum ​

xs.sort()[0] to find a min/max

Sorting is O(n log n) (and sort() mutates); finding the min or max is a single O(n) pass.

medium impact. Report only.

math-minmax-spread ​

Math.max(...xs) on large arrays

Spreading pushes every element onto the stack: slow for big arrays and a RangeError past ~100k elements. A loop is faster and safe.

medium impact. Report only.

typed-array-subarray ​

ta.slice(a, b) on a typed array → ta.subarray(a, b)

On a typed array, slice allocates a new buffer and copies the elements; subarray makes a view over the same memory in constant time. The view shares memory, so it is typed only when the result is read right away (indexOf, TextDecoder.decode, a spread into Math.max); otherwise writes to either array would show in the other.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.06×–3.16×, JavaScriptCore 0.99×–2×.

typed-array-round-trip ​

new Uint8Array(Array.from(ta)) or new Uint8Array([...ta]) → new Uint8Array(ta)

The plain array in the middle boxes every element and is thrown away. A typed array constructor copies another typed array directly, converting each element the same way.

medium impact. Fixes: typed. Measured speedup: V8 3.66×–89×, JavaScriptCore 8.14×–768×.

loops ​

foreach-to-for ​

xs.forEach(x => ...) → indexed for loop

An indexed loop has no per-element function call, so nothing has to be inlined. It is fastest in every engine tier, especially for large or polymorphic arrays. Holes in sparse arrays are skipped, as forEach does.

medium impact. Fixes: typed, assumed. Measured speedup: V8 0.96×–3.42×, JavaScriptCore 1.1×–3.72×.

for-of-to-indexed ​

for (const x of xs) → indexed for loop (proven arrays only)

for-of runs the iterator protocol. Optimizing compilers can remove that cost, but baseline tiers and cold code still pay it on every step, and an indexed loop never does.

low impact. Fixes: typed. Not in the recommended preset. Measured speedup: V8 1.17×–3.15×, JavaScriptCore 0.71×–1.46×.

for-in-array ​

for (const k in array) → indexed loop

for-in enumerates string keys, including inherited ones, through a slow generic path. Indices come back as strings, so every xs[k] also converts the key. Note: the fix makes the index a number.

high impact. Fixes: assumed. Measured speedup: V8 1.66×–34×, JavaScriptCore 3.44×–14×.

cache-array-length ​

for (let i = 0; i < xs.length; i++) → cache xs.length

Measured, it makes no difference once a loop is optimized: TurboFan, FTL and DFG already keep the length in a register (1.00–1.01x). It helps only in the interpreter and baseline tiers (about 1.2x on Sparkplug and LLInt), i.e. code that never gets hot. Off by default for that reason (bench/FINDINGS.md).

low impact. Fixes: typed, assumed. Not in the recommended preset. Measured speedup: V8 1×–1.22×, JavaScriptCore 1×–1.18×.

strings ​

split-join-to-replaceall ​

s.split(a).join(b) → s.replaceAll(a, b)

split/join allocates an array of every piece and then concatenates them again. replaceAll does a single pass. (Needs ES2021.)

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.62×–1.83×, JavaScriptCore 1.04×–1.44×.

regex-to-string-method ​

/^abc/.test(s) → s.startsWith('abc') (also endsWith, includes, ===)

Plain-text patterns don't need the regex engine. String methods skip regex compilation and matcher setup and are usually several times faster.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.15×–1.46×, JavaScriptCore 1.06×–1.2×.

match-to-test ​

s.match(re) / re.exec(s) used as a boolean → re.test(s)

match and exec allocate a result array with captures; test only returns a boolean.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.05×–1.27×, JavaScriptCore 0.94×–1.19×.

indexof-to-startswith ​

s.indexOf(x) === 0 → s.startsWith(x)

When the prefix is missing, indexOf keeps scanning the whole string. startsWith compares only the prefix.

medium impact. Fixes: typed, assumed. Measured speedup: V8 1.12×–3.1×, JavaScriptCore 1.05×–7.54×.

regexp-constructor-literal ​

new RegExp('a+b', 'g') with constant arguments → /a+b/g

A regex literal is parsed once and its compiled code is reused by the engine at that site. A constant RegExp constructor inside a function re-parses its source and looks up the cache on every call.

low impact. Fixes: exact. Measured speedup: V8 2.3×–6.33×, JavaScriptCore 1.52×–8.63×.

catastrophic-regex ​

Nested quantifiers like (a+)+ or (\w+\s?)*

A repeated group whose body can match the same text several ways backtracks exponentially when the match fails (ReDoS). Make the inner part unambiguous, or use a possessive-style rewrite.

high impact. Report only.

string-flatten-in-loop ​

A string grown with += and searched or indexed in the same loop

s += x builds a rope, which is cheap. A read such as s.charCodeAt(i), s[i] or s.indexOf(x) flattens the rope into one buffer, copying the whole string. Doing both in each iteration copies the string every time: O(n²). Keep what you need to read in a separate variable, or collect parts in an array and join once.

high impact. Report only.

regexp-in-loop ​

new RegExp(x) with the same x on every iteration of a loop

The pattern does not change between iterations, but each new RegExp allocates an object and looks the pattern up in the engine's regexp cache. Build it once before the loop. A hoisted regexp with the g or y flag keeps lastIndex between uses, so reset it or use String.prototype.match/replace, which do.

low impact. Report only.

objects ​

object-assign-to-spread ​

Object.assign({}, a, b) → { ...a, ...b }

Object spread into a fresh literal uses the engine's clone fast path (CloneObjectIC in V8). Object.assign goes through the generic [[Set]] path, one property at a time.

medium impact. Fixes: typed. Measured speedup: V8 1.06×–1.23×, JavaScriptCore 1.43×–1.73×.

object-entries-iteration ​

for (const [k] / [, v] of Object.entries(o)) → Object.keys / Object.values

Object.entries allocates a [key, value] array per property. A loop that uses only the keys or only the values gets them from Object.keys or Object.values without the pairs.

medium impact. Fixes: exact. Measured speedup: V8 2.21×–4.17×, JavaScriptCore 2.18×–14×.

delete-property ​

delete obj.prop

Deleting a property usually drops the object from fast hidden-class mode into slow dictionary mode for good. Set it to undefined, or use a Map for dynamic keys. On arrays, delete leaves a hole.

medium impact. Report only.

object-keys-emptiness ​

Object.keys(o).length === 0 to test for an empty object

This builds an array of every key just to see whether there is at least one. A for (const k in o) { if (Object.hasOwn(o, k)) return false } helper stops at the first key and allocates nothing.

medium impact. Report only.

large-object-literal ​

Large constant object/array literal → JSON.parse('...')

For big constant data (over ~10 kB), the JSON parser is much faster than the JavaScript parser and compiler, which have to handle a far richer grammar (see V8's "cost of JavaScript" guidance). The fix loses the static type in TypeScript, so it is only applied automatically in JS files.

medium impact. Fixes: typed, assumed (obscure). Not in the recommended preset.

object-keys-in-loop ​

Object.keys(o) (or values/entries) of an unchanged object inside a loop

Each call allocates a fresh array of every key (and, for entries, a pair per key). When the loop never changes the object, the result is the same every time: compute it once before the loop. In a loop condition (i < Object.keys(o).length) it is rebuilt on every iteration.

medium impact. Report only.

late-property ​

this.x = ... in a method for a field the class never declares or sets in its constructor

Engines give objects a shape (hidden class, Structure) from the properties they get at construction. Adding one later moves every instance to a new shape and can grow its property storage, and code that sees instances from before and after becomes polymorphic. Declare the field, or set it in the constructor (this.x = undefined).

low impact. Report only.

prototype-mutation ​

Object.setPrototypeOf, Reflect.setPrototypeOf or __proto__ = on an existing object

Changing an object's prototype after it exists invalidates the engine's assumptions about it and about code that has seen it; V8 and JSC both deoptimize, and the object may stay slow. Create it with the right prototype: Object.create(proto), a class, or { __proto__: proto, ... } in a literal.

medium impact. Report only.

typescript ​

downlevel-async ​

async compiled to generators by a target below ES2017

Below ES2017, TypeScript turns each async function into a generator driven by its __awaiter helper (async generators and for await need ES2018). Calls and awaits measured 2–14x slower than native async on V8 and JSC, at every tier. Every engine since 2017 runs native async, so raise target unless you ship to older ones.

medium impact. Report only.

define-class-fields ​

Class fields emitted as Object.defineProperty (useDefineForClassFields below ES2022)

With useDefineForClassFields: true and a target below ES2022, TypeScript writes every instance field as an Object.defineProperty call in the constructor. Constructing such objects measured 4–100x slower than native fields or plain assignment, on V8 and JSC. Set target to ES2022 or later (native fields keep the same semantics), or drop the option if nothing relies on define semantics.

high impact. Report only.

downlevel-private-fields ​

#private members compiled to WeakMaps by a target below ES2022

Below ES2022, TypeScript emulates #private fields and methods with a WeakMap or WeakSet per member and a checking helper on every access. Construction and access measured 5x to over 200x slower than native private fields, on V8 and JSC. Raise target to ES2022, or use TypeScript's private keyword, which emits a plain property.

high impact. Report only.

react ​

inline-prop-to-memo ​

A memo or PureComponent component given an object, array, function or element made during render

memo and PureComponent skip a render only when every prop is the same as last time (Object.is). An inline {}, [], arrow or JSX element is a new value on every render, so the component re-renders every time and also pays for the comparison. Hoist constants out of the component, and wrap the rest in useMemo or useCallback. With React Compiler, this is done for you.

medium impact. Report only.

inline-context-value ​

A context provider whose value is an object, array or function made during render

Every component that reads a context re-renders when its value changes (Object.is), however deep it is and even inside memo. A value= built in render is new each time, so every consumer re-renders whenever the provider does. Wrap the value in useMemo (and its functions in useCallback), or hoist it. With React Compiler, this is done for you.

medium impact. Report only.

unstable-key ​

A JSX key from Math.random(), crypto.randomUUID(), Date.now() or a fresh id

React matches elements across renders by key. A key that changes on every render makes React unmount the old element and mount a new one each time: its whole subtree is rebuilt, its DOM replaced, and its state and effects reset. Key by a stable id from the data, or generate ids once, when the data is created.

high impact. Report only.

misc ​

date-now ​

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

Date.now() returns the timestamp without allocating a Date object.

low impact. Fixes: exact. Measured speedup: V8 1.47×–1.61×, JavaScriptCore 1.03×–1.34×.

math-pow-to-mul ​

Math.pow(x, 2) / x ** 2 → x * x

Squaring with a multiply is one instruction, while pow goes through the generic power routine (or a builtin call in lower tiers). The results are bit-identical for numbers.

low impact. Fixes: typed, assumed. Measured speedup: V8 1.07×–1.47×, JavaScriptCore 0.75×–2.87×.

bitwise-trunc ​

Math.trunc(x) / Math.floor(x) → x | 0 (int32 only)

x | 0 truncates to a 32-bit integer in one instruction and tells the JIT the value is a small integer, which keeps the arithmetic after it in int32. It is wrong outside ±2³¹ and for negative values with floor, so the fix is unsafe: only use it where you know the range.

low impact. Fixes: assumed (obscure). Not in the recommended preset. Measured speedup: V8 1.15×–1.56×, JavaScriptCore 0.76×–1.37×.

dynamic-code ​

eval, new Function, and with

Direct eval and with make every variable in the enclosing scopes dynamically resolvable, which blocks inlining and register allocation for those functions. new Function re-parses and compiles its source on every call.

high impact. Report only.

dom-in-loop ​

DOM queries and layout reads inside loops

Querying the DOM walks the tree. Layout reads such as offsetHeight or getBoundingClientRect force a synchronous reflow when styles are dirty, and interleaving them with writes in a loop causes layout thrashing. Query once and batch reads before writes.

high impact. Report only.

arguments-object ​

arguments that escapes, or is written → rest parameters

Optimizing compilers never allocate arguments when the function only reads arguments.length or arguments[i], or passes it to f.apply(this, arguments). Passing it anywhere else, storing it, or writing to it forces a real object (in sloppy mode one that aliases the parameters). Rest parameters give a real array and are always cheap.

low impact. Report only.

postmessage-transfer ​

postMessage(buffer) of an ArrayBuffer or typed array without a transfer list

Without a transfer list, postMessage copies the whole buffer (structured clone). Transferring moves it in constant time: postMessage(ta, [ta.buffer]) for a worker or port, postMessage(ta, origin, [ta.buffer]) for a window. The sender's buffer is then detached, so only do it when the sender is done with it.

medium impact. Report only.

passive-listener ​

wheel/touchstart/touchmove listener that never calls preventDefault, without { passive: true }

The browser cannot scroll until a non-passive wheel or touch listener returns, because it might call preventDefault. A listener that never does can say so with { passive: true }, and scrolling no longer waits for it.

medium impact. Fixes: typed, assumed.

scroll-layout-read ​

A scroll or resize listener that reads layout

Scroll and resize fire many times per frame, and each layout read (getBoundingClientRect, offsetTop) can force a synchronous reflow. IntersectionObserver answers visibility questions and ResizeObserver size ones without polling; otherwise read once per frame inside requestAnimationFrame.

medium impact. Report only.

gpu-sync-in-frame ​

gl.getError(), getParameter, readPixels and other GPU round trips inside a frame callback

WebGL calls are queued for the GPU. A query such as getError or readPixels makes the CPU wait until the queue drains, every frame, which stalls the pipeline. Check errors only in debug builds, cache parameters at start-up, and read pixels asynchronously (a pixel buffer and fenceSync in WebGL2).

high impact. Report only.

per-frame-allocation ​

WebGL objects, canvas contexts or typed arrays created inside a frame callback

Creating GPU buffers and textures, looking up a canvas context, or allocating typed arrays on every frame churns GPU memory and the garbage collector, which shows up as dropped frames. Create them once and reuse them (bufferSubData, texSubImage2D, a scratch typed array).

medium impact. Report only.

Retired ​

These rules never run: their fix measured slower. They are kept so a run on newer engines can bring them back.

array-from-map ​

Array.from(x).map(f) → Array.from(x, f)

Array.from takes a map function, which avoids building the array twice.

low impact. Fixes: typed, assumed. Measured speedup: V8 0.13×–0.64×, JavaScriptCore 0.56×–0.97×.

Retired

the fix is slower on every V8 and JSC tier (TurboFan 0.12–0.15x); see bench/FINDINGS.md, 2026-11-16

object-entries-pair ​

for (const [k, v] of Object.entries(o)) → Object.keys plus o[k]

Object.entries allocates a [key, value] array per property, and destructuring each one goes through the iterator protocol. Keys plus an index load avoid all of that.

medium impact. Fixes: assumed. Measured speedup: V8 0.1×–2.28×, JavaScriptCore 0.84×–5.96×.

Retired

the fix is slower on V8's top tiers (TurboFan 0.10–0.61x), though faster on JSC at 10 keys; see bench/FINDINGS.md, 2026-11-16

Released under the MIT License.