loadwise perf finds repeated backend work and avoidable React, Vue and Angular rendering work in source code, OpenTelemetry traces and executed database plans. Findings for loops and repeated spans carry an Impact: line that says which side is measured and which is estimated (~); a millisecond figure is never printed without a measurement behind it.
Sample text finding with its fix diff:
Source checks
Run in the directory containingtsconfig.json or jsconfig.json, pass -p path/to/config.json, or give explicit JS/TS files (checked with ES2022 and NodeNext defaults). A project check follows project references. JavaScript files that the found config leaves out because allowJs is off are still checked with the standalone defaults and named in a note; a config passed with -p is checked exactly as it lists its files. Install the application’s driver declarations and generate its Prisma client first: unresolved types, wrappers and deferred callbacks can hide findings. Test, seed and operator-tooling sources (scripts, seeds, prisma/seed.ts, *.seed.ts, deployment, migrations) make per-item query, index, serial-await, Redis KEYS, pure-JavaScript hashing, Prisma dependent-write and Drizzle whole-table-write findings contextual. prisma-count-for-existence findings may carry idField, the model’s single primary-key field that the fix selects.
Engines: one-shot checks use Microsoft’s Go-based TypeScript 7 compiler on Node.js 22.13+ with the optional native package for your platform (same findings; 1.7–2.2 times faster on the 3,200-file benchmark in PERFORMANCE.md, and the gain depends on the project) and fall back to TypeScript 6.0.3 with a stderr note when TypeScript 7 rejects the configuration (for example baseUrl or moduleResolution: "node10"). --engine native (alias --native) requires TypeScript 7 and reports incompatible configuration as exit 2; --engine js always uses TypeScript 6.0.3. perf --json names the engine in engine ("js" or "native"). --watch uses TypeScript 6.0.3 on a single project; with --watch --json each completed scan writes one JSON line.
If your npm registry omits the optional native TypeScript packages, install with those dependencies omitted and scan with the JavaScript compiler:
engine to "js". Explicit native mode (--engine native or --native) requires the matching TypeScript binary and exits 2 if it is missing.
--omit=optional also removes @ast-grep/cli. JavaScript and TypeScript source checks still run, but polyglot checks skip Python, Go, Java, C#, and Rust until the optional scanner is installed.
angular-default-change-detection(low): An Angular component uses default change detection instead of OnPush, so its subtree is re-checked on every event.angular-ngfor-missing-trackby(low): An *ngFor has no trackBy, so a list replaced with new objects recreates the DOM of every item.angular-subscribe-without-cleanup(medium): An RxJS subscription in a component has no completing operator or ngOnDestroy unsubscribe and keeps running after destruction.array-repeated-find(medium): An array is searched with find or findIndex repeatedly where a Map lookup would do.array-repeated-membership(medium): An array is tested with includes or indexOf repeatedly where a Set would do.array-shift-in-fifo-drain(low): A FIFO drain repeatedly removes the first array element.dom-layout-thrashing(medium): A loop reads layout metrics and mutates DOM styles or classes, forcing a reflow on each iteration.dom-listener-without-cleanup(low): A window or document listener uses an inline function with no AbortSignal or once, so it can never be removed.dom-unthrottled-scroll-resize(low): A scroll, resize, mousemove, wheel or touch listener runs unthrottled work (or is non-passive) on the main thread.express-missing-compression(low): An Express server registers no response compression middleware.external-call-in-transaction(high): An external call is awaited inside a database transaction, holding its connection and locks.filter-for-existence(low): filter(…).length is used only to test whether any element matches.frontend-barrel-heavy-import(low): A client module imports the whole of lodash or moment instead of subpaths or a lighter library.graphql-n-plus-one-resolver(high): A GraphQL field resolver executes a database or HTTP query per parent item without DataLoader batching.heavy-media-in-request-handler(medium): Heavy image (sharp) or PDF rendering runs directly inside an HTTP request handler.js-fixed-regexp-in-loop(low): A stateless RegExp is repeatedly constructed from fixed arguments.json-roundtrip-clone(low): A value is deep-cloned with JSON.parse(JSON.stringify(…)) on a request path.json-stringify-in-loop(medium): JSON.stringify runs inside a loop instead of serializing once or streaming.list-count-per-request(medium): A list endpoint runs a full count query on every request.list-query-overfetch(medium): A list query loads large columns or nested relations without a narrow projection.llm-call-without-max-tokens(medium): An OpenAI chat or responses call sets no output token limit.loop-copy-accumulator(medium): A loop copies its growing result on every iteration.mongoose-hydrate-for-to-object(medium): A Mongoose query hydrates full Documents only to convert them immediately via .toObject() or .toJSON().mongoose-missing-lean(medium): A Mongoose read query is returned or serialized without .lean(), paying full Document hydration overhead.node-event-listener-leak(high): An event listener is registered inside a repeated or per-request context without matching cleanup.node-sync-compression-in-async(medium): A synchronous zlib call blocks the event loop inside an async function.node-sync-crypto-in-async(high): A synchronous crypto call blocks the event loop inside an async function.node-sync-fs-in-async(medium): A synchronous fs call blocks the event loop inside an async function.node-sync-process-in-async(high): A synchronous child_process call blocks the event loop inside an async function.notification-send-in-loop(high): A push, email or Firebase message is sent once per loop iteration instead of in one batch.orm-cartesian-include(high): One query joins two or more one-to-many relations, so the returned rows multiply.orm-deep-offset(high): A list query pages with a large or unbounded offset, so the database reads and discards every skipped row.password-hash-pure-js(medium): bcryptjs hashes passwords in pure JavaScript on the main thread.password-hash-sync-in-async(high): A synchronous bcrypt call blocks the event loop inside an async function.pg-count-materialization(medium): A pg query loads rows only to count them.pg-filter-materialization(medium): A pg query loads an unbounded result that JavaScript then filters by equality.pg-first-materialization(medium): A pg query loads an unbounded result to read only its first row.pg-query-in-loop(high): A pg query runs once per loop iteration.pg-top-k-materialization(medium): A pg query loads an unbounded result that JavaScript sorts to keep the top rows.pg-unreleased-checkout(critical): A chained pool checkout loses the client, so it is never released.pool-created-per-request-or-item(critical): A database, Redis, S3, OpenAI, Anthropic or Stripe client or pool is created on a per-request or per-item path.prisma-count-materialization(medium): A Prisma query loads rows only to count them.prisma-filter-materialization(medium): A Prisma query loads an unbounded result that JavaScript then filters by equality.prisma-first-materialization(medium): A Prisma query loads an unbounded result to read only its first row.prisma-query-in-loop(high): A Prisma query runs once per loop iteration.prisma-top-k-materialization(medium): A Prisma query loads an unbounded result that JavaScript sorts to keep the top rows.queue-add-in-loop(high): A job queue add runs once per item instead of one addBulk.react-component-defined-in-component(medium): A component is declared inside another component and rendered as an element, so it remounts on every render and loses its state and DOM.react-context-value-recreated(low): An inline object or array literal in Context.Provider value creates a new reference on every render.react-fetch-in-effect-no-abort(low): A fetch in an effect has no AbortController or cleanup, so dependency changes can race and apply stale results.react-index-as-key(low): A list item uses the map index as its React key, which breaks reconciliation when items are inserted or reordered.react-inline-object-in-jsx-prop(low): An inline object literal is passed to a memo() component, creating a new reference each render and defeating the memo.react-missing-cleanup(medium): An effect starts a global listener, interval, socket or endless subscription and returns no cleanup, so it leaks on every remount.rebuild-lookup-in-loop(high): A Set or Map is rebuilt from the same data on every loop iteration.redis-command-in-loop(high): A per-key Redis command runs once per loop iteration.redis-keys-command(high): A Redis KEYS call blocks the server while it scans the keyspace.reduce-copy-accumulator(medium): A reduce callback copies its growing accumulator on every step.sequential-http-in-loop(high): Independent HTTP requests are awaited one at a time inside a loop.serial-awaits-in-literal(medium): An array or object literal awaits two or more independent values one after another.service-query-in-loop(high): A loop calls a project function that runs several database operations per item.session-memory-store(high): An express-session middleware has no store, so sessions live in process memory.sql-select-star-in-query(low): A raw SQL query selects every column with SELECT * instead of the columns it needs.unbounded-list-query(high): A request handler returns query results without an apparent row limit.unbounded-module-cache(medium): A long-lived cache accepts dynamic keys without an apparent bound or eviction.vue-v-for-missing-key(low): A list rendered with h() or v-for has no key, so Vue cannot reliably reuse matching nodes.vue-watch-missing-cleanup(medium): onMounted registers a global listener, timer or observer with no unmount cleanup.whole-payload-in-memory(medium): An operation loads an entire file, stream, or response into memory.
ORM and query integrity checks
Covered libraries: Prisma, Drizzle ORM (PostgreSQL, MySQL and SQLite core APIs), TypeORM, Sequelize, Mongoose, Knex, Kysely and node-postgres. Building an array of lazy Prisma queries alone is quiet, and same-tickfindUnique calls that Prisma batches itself are left to runtime traces.
drizzle-query-in-loop(high): A Drizzle statement executes once per loop iteration.guard-query-per-request(medium): A guard or per-request hook runs a database query before every handler.orm-count-materialization(medium): A TypeORM, Sequelize, Mongoose, Knex or Kysely query loads rows only to count them.orm-query-in-loop(high): A TypeORM, Sequelize, Mongoose, Knex or Kysely operation runs once per loop iteration.prisma-distinct-in-memory(medium): Prisma findMany with distinct reads every matching row and de-duplicates in memory.prisma-relation-count-in-list(medium): A paged Prisma findMany selects a relation _count computed over the whole related table.typeorm-existence-materialization(medium): A TypeORM entity is loaded only to check whether it exists.typeorm-load-then-save(high): A TypeORM entity is loaded only to change a few fields and save it back.typeorm-transaction-in-loop(high): A loop calls a helper that starts one TypeORM transaction per item.typeorm-wide-projection(low): A TypeORM DTO projection loads wide columns it never uses.
Project-defined access policy
Put the policy in theperformance section of loadwise.config.json beside the selected project config (in the working directory for explicit source files), or pass --policy path/to/file.json. A policy can use just the sections the project needs: parallelReads (groups of exports that may start together, used by known-reads-awaited-serially), fireAndForget (helper names that floating-promise accepts without an await), and prismaScopes, drizzleScopes and kyselyScopes (see Project-defined row scopes). Duplicate JSON keys within the same object produce a configuration error. Example policy
Async work and sorting
await-before-early-exit(medium): An awaited read runs before a guard that returns or throws without using its result.count-then-page-serial(low): A count and a page query with the same filter run one after the other.drizzle-last-insert-id(medium): A MySQL insert is followed by an extra query for its generated ID.known-reads-awaited-serially(medium): Two independent reads from a configured parallelReads group are awaited one after the other.next-server-fetch-waterfall(medium): A Next.js Server Component page awaits independent GET requests in sequence.numeric-sort-for-extreme(low): A numeric sort is used only to read the smallest or largest value.prisma-count-for-existence(medium): A Prisma query counts all matches only to check whether any row exists.promise-combinator-serial-await(medium): Promise.all receives calls that were already awaited one by one.repeated-workbook-decode(medium): A workflow decodes the same input with ExcelJS more than once.typeorm-unused-count(medium): A TypeORM count-and-list query discards its total in immediate tuple destructuring.
Schema-aware index checks
The source checker reads the project’s ORM schema (Prisma, Drizzle, TypeORM, Sequelize, Mongoose) and compares declared indexes with the queries it finds. Each suggested index carries one explicit name, used both in the ORM snippet and in theCREATE INDEX CONCURRENTLY statement, so building it by hand and then generating a migration does not create a duplicate. Pass --schema snapshot.json (written by perf db --schema-snapshot) to refine findings with real table sizes and the measured round trip, which also feeds the Impact line of *-query-in-loop findings.
index-missing-filter(high): A query filters on a column that no index leads with.index-missing-foreign-key(high): A foreign key column in the schema has no index.index-missing-order(medium): A query orders by columns that no index serves in that order.index-redundant-prefix(low): An index repeats the leading columns of a longer index on the same table, adding write cost for no read benefit.index-unusable-expression(high): A function or expression on an indexed column keeps the index from being used.index-unusable-pattern(high): A predicate such as a leading-wildcard LIKE cannot use an ordinary index.
Polyglot source checks
npx loadwise perf polyglot src accepts directories or individual .py, .go, .java, .cs, .rs, .rb and .php files and needs the optional ast-grep native binary. npx loadwise rel polyglot src runs its reliability patterns for Python, Go, Java, C#, Rust and Kotlin (.kt, .kts). Language-specific aliases and wrappers can fall outside a pattern.
csharp-ef-count-materialized(medium): An EF Core DbSet is materialized solely to count its rows.csharp-ef-query-in-loop(medium): An EF Core DbSet query executes for each loop key.csharp-fixed-regex-in-loop(medium): A C# Regex with a fixed pattern is constructed inside a loop.csharp-string-concat-in-loop(medium): String concatenation in a C# loop allocates repeatedly; use StringBuilder.go-fixed-regexp-in-loop(medium): A Go regexp with a fixed pattern is compiled inside a loop.go-sql-query-in-loop(high): A Go database query executes inside a loop instead of batching.go-string-concat-in-loop(medium): String concatenation in a Go loop allocates repeatedly; use strings.Builder.java-fixed-regex-in-loop(medium): A Java Pattern with a fixed pattern is compiled inside a loop.java-jdbc-query-in-loop(high): A JDBC query executes inside a Java loop instead of batching.java-string-concat-in-loop(medium): String concatenation in a Java loop allocates repeatedly; use StringBuilder.php-eloquent-query-in-loop(medium): An Eloquent key lookup runs for each PHP foreach item.python-blocking-sleep-in-async(high): A blocking time.sleep call runs inside a Python async def function.python-copy-growing-list(medium): A Python loop rebuilds a growing list with items = items + [value].python-fixed-regex-in-loop(low): A Python loop repeatedly looks up a fixed pattern in the re.compile cache.python-n-plus-one-orm-loop(high): An ORM query executes inside a Python loop instead of using eager loading or batching.python-sync-requests-in-async(high): A blocking requests HTTP call runs inside a Python async def function.python-unbounded-comprehension(medium): A Python list comprehension materializes an unbounded collection in memory.ruby-active-record-query-in-loop(medium): A Ruby loop performs one Active Record lookup per item.rust-clone-in-loop(low): Cloning values inside a Rust loop adds avoidable heap allocations.rust-fixed-regex-in-loop(medium): A Rust Regex with a fixed pattern is compiled inside a loop.rust-format-in-loop(low): Calling format! inside a Rust loop allocates a new String on every iteration.
Trace checks in other languages and databases
npx loadwise perf traces <file> reads one local OTLP, Jaeger, or Zipkin v2 JSON export. For OpenTelemetry Collector output with multiple JSON lines, pass the export object for the request. --threshold sets how many similar sibling calls form a finding. Try npx loadwise perf traces node_modules/loadwise/examples/repeated-db.otlp.json. Reports contain span IDs and counts and omit raw SQL, parameters and keys. Check scannedSpans and eligibleDbSpans when interpreting a clean result.
duplicate-key-read(medium): A trace repeats the same key or row read under one parent span.redis-keys-scan(high): A trace shows a Redis KEYS command scanning the keyspace.redis-repeated-read(medium): A trace shows repeated sibling Redis GET or HGET calls.repeated-db-span(high): A trace shows many similar sibling database calls under one parent.
Executed query plans
npx loadwise perf plan <file> reads a JSON file from PostgreSQL EXPLAIN (ANALYZE, FORMAT JSON) or MongoDB explain("executionStats"), for example node_modules/loadwise/examples/postgres-plan.json, and reports the stage path and observed counts (MongoDB: classic stages and selected slot-based scan, filter and skip shapes). Planner estimates alone, and layouts where a scan cannot be attributed, exit 2. PostgreSQL’s ANALYZE option executes the statement when you collect the plan.
mongo-collection-scan(high): A MongoDB plan scans many documents for each one it returns.mongo-deep-skip(high): A MongoDB query skips past many documents to return a page.mongo-disk-sort(medium): A MongoDB sort spilled to disk.pg-deep-offset(high): A PostgreSQL plan walks past many rows with OFFSET to return a page.pg-disk-sort(medium): A PostgreSQL sort spilled to disk.pg-sequential-scan(high): A PostgreSQL plan scans many rows for each one it returns.
Database inspection (optional)
npx loadwise perf db is the only command that connects to a database. Point it at a staging or read replica database, never a primary you cannot afford to touch. It uses the project’s own pg, mysql2 or mongodb package.
The connection comes from the environment, never a flag: DATABASE_URL (or the variable named by --url-env), else DB_HOST, DB_PORT, DB_USER or DB_USERNAME, DB_PASSWORD and DB_NAME or DB_DATABASE. --env-file FILE reads those variables from a file without loading them into the process environment. --engine postgres|mysql|mongo is needed with DB_HOST variables when DB_PORT is not the engine default. For MySQL without TLS, mysql2 3.26.0 and later refuse to fetch the server’s RSA public key, which an account that has not logged in since the server started needs; connect with TLS (preferred), or opt in with DB_ALLOW_PUBLIC_KEY_RETRIEVAL=1 or ?allowPublicKeyRetrieval=true on the URL. Opting in lets a man-in-the-middle on an untrusted network read the password. It is off by default.
--include-contextual, --ignore RULE and --json work as in the other commands.
For a local SQLite file, use loadwise perf db --engine sqlite --sqlite-file app.sqlite --queries queries.sql. Loadwise opens the file read-only with Node’s SQLite module and returns EXPLAIN QUERY PLAN details for SELECT statements. It skips other statements, leaves the SELECTs unevaluated, and uses no project driver. On Node 22, Node prints an ExperimentalWarning for its SQLite module on each run; the warning does not affect the result.
db-duplicate-index(low): A database index is covered by another index on the same table.db-missing-index(high): A query plan scans a table that a suggested index would let it seek.db-seq-scan-heavy-table(high): A large table is read by many sequential scans on the live database.db-slow-query-plan(high): A plan uses full scans or large MySQL filesorts or temporary tables.db-sqlite-large-scan(medium): A filtered SQLite query plans an unindexed scan of a large table.db-unindexed-foreign-key(high): A foreign key on the live database has no index that leads with its columns.db-unused-index(low): A database index has not been scanned since statistics were last reset.mongo-collection-scan-observed(high): Profiled MongoDB operations scanned a whole collection.
EXPLAIN ANALYZE runs only for a plain SELECT (a WITH that modifies data is refused). MongoDB uses a command allowlist. Error text replaces the connection URL, host, user, password and resolved IP addresses with [redacted]. Usage counters come from the node that answered, so an index unused here may still be used on a replica.
--measure blocks writes to the table while each index builds. It refuses a connection variable or database name matching /prod/i, a replica, an unknown table size and any table over 5,000,000 estimated rows, and it needs the long confirmation flag. With the HypoPG extension, suggested indexes are also checked hypothetically. Output labels every figure as measured (timed on your database) or estimated (planner statistics, a model or HypoPG).