For code on frequently executed paths (request handling, routing, serialization, middleware), base optimization decisions on actual benchmarks rather than assumptions, and avoid introducing redundant work. Concretely:
mitata or console.time, and include the comparison in the PR description when the change trades readability/DRYness for speed.// Good: regex compiled once const SPLIT_REGEX = /;(?=(?:(?:[^”]”){2})[^”]*$)/ const parseValue = (value: string) => value.split(SPLIT_REGEX) ```
/%/.test(str) before decoding, str.includes(...) before a replace) over always running the expensive operation, and prefer constructing objects (e.g. new Response()) with the minimal set of options needed.Response.json()) is simpler and measurably at least as fast as a hand-rolled equivalent, prefer it.The goal is to make performance-sensitive changes deliberate, measured, and scoped to the code that actually executes on every request, rather than guessing or optimizing cold paths at the expense of clarity.