> ## Documentation Index
> Fetch the complete documentation index at: https://loadwise.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Performance checker

> loadwise perf: repeated backend work, rendering work, schema-aware indexes, traces, query plans and database inspection.

`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:

```text theme={null}
examples/slow.ts:7:48 [array-repeated-find #9ab891a8b8f7] medium: Each item can rescan the lookup array with find(), so cost grows with items times rows. Build `const byKey = new Map()` once (first match wins) and call `byKey.get(key)`; keep the original key-equality semantics.
  Fix (examples/slow.ts:7):
    - const names = visible.map(order => customers.find(customer => customer.id === order.customerId)?.name ?? 'Unknown');
    + const customersById = new Map(customers.map((customer) => [customer.id, customer] as const).reverse());
    + const names = visible.map(order => customersById.get(order.customerId)?.name ?? 'Unknown');
```

| Input | Command after `npx loadwise perf` | Needs a database |
| - | - | - |
| JavaScript or TypeScript | `-p tsconfig.json`, `--watch -p tsconfig.json` or `src/handler.ts` | No |
| Schema-aware index checks | `--schema snapshot.json` | No (snapshot) |
| Python, Go, Java, C#, Rust, Ruby, PHP | `polyglot src` | No |
| OTLP/JSON from any application language | `traces request.otlp.json --threshold 5` | No |
| Executed PostgreSQL or MongoDB plan | `plan explain.json` | No |
| Live database inspection | `db` | Yes, read-only unless `--measure` |

## Source checks

Run in the directory containing `tsconfig.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](https://github.com/microsoft/typescript-go) 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](https://github.com/IbrahimHafez1/loadwise/blob/main/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:

```sh theme={null}
npm install --save-dev --omit=optional loadwise
npx loadwise perf --engine js --json
```

Automatic engine selection also falls back to JavaScript when the optional binary is absent. The report sets `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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/array-repeated-find) (medium): An array is searched with find or findIndex repeatedly where a Map lookup would do.
* [`array-repeated-membership`](https://loadwise.mintlify.site/rules/performance/array-repeated-membership) (medium): An array is tested with includes or indexOf repeatedly where a Set would do.
* [`array-shift-in-fifo-drain`](https://loadwise.mintlify.site/rules/performance/array-shift-in-fifo-drain) (low): A FIFO drain repeatedly removes the first array element.
* [`dom-layout-thrashing`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/express-missing-compression) (low): An Express server registers no response compression middleware.
* [`external-call-in-transaction`](https://loadwise.mintlify.site/rules/performance/external-call-in-transaction) (high): An external call is awaited inside a database transaction, holding its connection and locks.
* [`filter-for-existence`](https://loadwise.mintlify.site/rules/performance/filter-for-existence) (low): filter(...).length is used only to test whether any element matches.
* [`frontend-barrel-heavy-import`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/heavy-media-in-request-handler) (medium): Heavy image (sharp) or PDF rendering runs directly inside an HTTP request handler.
* [`js-fixed-regexp-in-loop`](https://loadwise.mintlify.site/rules/performance/js-fixed-regexp-in-loop) (low): A stateless RegExp is repeatedly constructed from fixed arguments.
* [`json-roundtrip-clone`](https://loadwise.mintlify.site/rules/performance/json-roundtrip-clone) (low): A value is deep-cloned with JSON.parse(JSON.stringify(...)) on a request path.
* [`json-stringify-in-loop`](https://loadwise.mintlify.site/rules/performance/json-stringify-in-loop) (medium): JSON.stringify runs inside a loop instead of serializing once or streaming.
* [`list-count-per-request`](https://loadwise.mintlify.site/rules/performance/list-count-per-request) (medium): A list endpoint runs a full count query on every request.
* [`list-query-overfetch`](https://loadwise.mintlify.site/rules/performance/list-query-overfetch) (medium): A list query loads large columns or nested relations without a narrow projection.
* [`llm-call-without-max-tokens`](https://loadwise.mintlify.site/rules/performance/llm-call-without-max-tokens) (medium): An OpenAI chat or responses call sets no output token limit.
* [`loop-copy-accumulator`](https://loadwise.mintlify.site/rules/performance/loop-copy-accumulator) (medium): A loop copies its growing result on every iteration.
* [`mongoose-hydrate-for-to-object`](https://loadwise.mintlify.site/rules/performance/mongoose-hydrate-for-to-object) (medium): A Mongoose query hydrates full Documents only to convert them immediately via .toObject() or .toJSON().
* [`mongoose-missing-lean`](https://loadwise.mintlify.site/rules/performance/mongoose-missing-lean) (medium): A Mongoose read query is returned or serialized without .lean(), paying full Document hydration overhead.
* [`node-event-listener-leak`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/node-sync-compression-in-async) (medium): A synchronous zlib call blocks the event loop inside an async function.
* [`node-sync-crypto-in-async`](https://loadwise.mintlify.site/rules/performance/node-sync-crypto-in-async) (high): A synchronous crypto call blocks the event loop inside an async function.
* [`node-sync-fs-in-async`](https://loadwise.mintlify.site/rules/performance/node-sync-fs-in-async) (medium): A synchronous fs call blocks the event loop inside an async function.
* [`node-sync-process-in-async`](https://loadwise.mintlify.site/rules/performance/node-sync-process-in-async) (high): A synchronous child\_process call blocks the event loop inside an async function.
* [`notification-send-in-loop`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/orm-cartesian-include) (high): One query joins two or more one-to-many relations, so the returned rows multiply.
* [`orm-deep-offset`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/password-hash-pure-js) (medium): bcryptjs hashes passwords in pure JavaScript on the main thread.
* [`password-hash-sync-in-async`](https://loadwise.mintlify.site/rules/performance/password-hash-sync-in-async) (high): A synchronous bcrypt call blocks the event loop inside an async function.
* [`pg-count-materialization`](https://loadwise.mintlify.site/rules/performance/pg-count-materialization) (medium): A pg query loads rows only to count them.
* [`pg-filter-materialization`](https://loadwise.mintlify.site/rules/performance/pg-filter-materialization) (medium): A pg query loads an unbounded result that JavaScript then filters by equality.
* [`pg-first-materialization`](https://loadwise.mintlify.site/rules/performance/pg-first-materialization) (medium): A pg query loads an unbounded result to read only its first row.
* [`pg-query-in-loop`](https://loadwise.mintlify.site/rules/performance/pg-query-in-loop) (high): A pg query runs once per loop iteration.
* [`pg-top-k-materialization`](https://loadwise.mintlify.site/rules/performance/pg-top-k-materialization) (medium): A pg query loads an unbounded result that JavaScript sorts to keep the top rows.
* [`pg-unreleased-checkout`](https://loadwise.mintlify.site/rules/performance/pg-unreleased-checkout) (critical): A chained pool checkout loses the client, so it is never released.
* [`pool-created-per-request-or-item`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/prisma-count-materialization) (medium): A Prisma query loads rows only to count them.
* [`prisma-filter-materialization`](https://loadwise.mintlify.site/rules/performance/prisma-filter-materialization) (medium): A Prisma query loads an unbounded result that JavaScript then filters by equality.
* [`prisma-first-materialization`](https://loadwise.mintlify.site/rules/performance/prisma-first-materialization) (medium): A Prisma query loads an unbounded result to read only its first row.
* [`prisma-query-in-loop`](https://loadwise.mintlify.site/rules/performance/prisma-query-in-loop) (high): A Prisma query runs once per loop iteration.
* [`prisma-top-k-materialization`](https://loadwise.mintlify.site/rules/performance/prisma-top-k-materialization) (medium): A Prisma query loads an unbounded result that JavaScript sorts to keep the top rows.
* [`queue-add-in-loop`](https://loadwise.mintlify.site/rules/performance/queue-add-in-loop) (high): A job queue add runs once per item instead of one addBulk.
* [`react-component-defined-in-component`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/rebuild-lookup-in-loop) (high): A Set or Map is rebuilt from the same data on every loop iteration.
* [`redis-command-in-loop`](https://loadwise.mintlify.site/rules/performance/redis-command-in-loop) (high): A per-key Redis command runs once per loop iteration.
* [`redis-keys-command`](https://loadwise.mintlify.site/rules/performance/redis-keys-command) (high): A Redis KEYS call blocks the server while it scans the keyspace.
* [`reduce-copy-accumulator`](https://loadwise.mintlify.site/rules/performance/reduce-copy-accumulator) (medium): A reduce callback copies its growing accumulator on every step.
* [`sequential-http-in-loop`](https://loadwise.mintlify.site/rules/performance/sequential-http-in-loop) (high): Independent HTTP requests are awaited one at a time inside a loop.
* [`serial-awaits-in-literal`](https://loadwise.mintlify.site/rules/performance/serial-awaits-in-literal) (medium): An array or object literal awaits two or more independent values one after another.
* [`service-query-in-loop`](https://loadwise.mintlify.site/rules/performance/service-query-in-loop) (high): A loop calls a project function that runs several database operations per item.
* [`session-memory-store`](https://loadwise.mintlify.site/rules/performance/session-memory-store) (high): An express-session middleware has no store, so sessions live in process memory.
* [`sql-select-star-in-query`](https://loadwise.mintlify.site/rules/performance/sql-select-star-in-query) (low): A raw SQL query selects every column with SELECT \* instead of the columns it needs.
* [`unbounded-list-query`](https://loadwise.mintlify.site/rules/performance/unbounded-list-query) (high): A request handler returns query results without an apparent row limit.
* [`unbounded-module-cache`](https://loadwise.mintlify.site/rules/performance/unbounded-module-cache) (medium): A long-lived cache accepts dynamic keys without an apparent bound or eviction.
* [`vue-v-for-missing-key`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/vue-watch-missing-cleanup) (medium): onMounted registers a global listener, timer or observer with no unmount cleanup.
* [`whole-payload-in-memory`](https://loadwise.mintlify.site/rules/performance/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-tick `findUnique` calls that Prisma batches itself are left to runtime traces.

* [`drizzle-query-in-loop`](https://loadwise.mintlify.site/rules/performance/drizzle-query-in-loop) (high): A Drizzle statement executes once per loop iteration.
* [`guard-query-per-request`](https://loadwise.mintlify.site/rules/performance/guard-query-per-request) (medium): A guard or per-request hook runs a database query before every handler.
* [`orm-count-materialization`](https://loadwise.mintlify.site/rules/performance/orm-count-materialization) (medium): A TypeORM, Sequelize, Mongoose, Knex or Kysely query loads rows only to count them.
* [`orm-query-in-loop`](https://loadwise.mintlify.site/rules/performance/orm-query-in-loop) (high): A TypeORM, Sequelize, Mongoose, Knex or Kysely operation runs once per loop iteration.
* [`prisma-distinct-in-memory`](https://loadwise.mintlify.site/rules/performance/prisma-distinct-in-memory) (medium): Prisma findMany with distinct reads every matching row and de-duplicates in memory.
* [`prisma-relation-count-in-list`](https://loadwise.mintlify.site/rules/performance/prisma-relation-count-in-list) (medium): A paged Prisma findMany selects a relation \_count computed over the whole related table.
* [`typeorm-existence-materialization`](https://loadwise.mintlify.site/rules/performance/typeorm-existence-materialization) (medium): A TypeORM entity is loaded only to check whether it exists.
* [`typeorm-load-then-save`](https://loadwise.mintlify.site/rules/performance/typeorm-load-then-save) (high): A TypeORM entity is loaded only to change a few fields and save it back.
* [`typeorm-transaction-in-loop`](https://loadwise.mintlify.site/rules/performance/typeorm-transaction-in-loop) (high): A loop calls a helper that starts one TypeORM transaction per item.
* [`typeorm-wide-projection`](https://loadwise.mintlify.site/rules/performance/typeorm-wide-projection) (low): A TypeORM DTO projection loads wide columns it never uses.

### Project-defined access policy

Put the policy in the `performance` 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](https://loadwise.mintlify.site/checkers/security.md#project-defined-row-scopes)). Duplicate JSON keys within the same object produce a configuration error. [Example policy](https://github.com/IbrahimHafez1/loadwise/blob/main/examples/query-policy.json)

### Async work and sorting

* [`await-before-early-exit`](https://loadwise.mintlify.site/rules/performance/await-before-early-exit) (medium): An awaited read runs before a guard that returns or throws without using its result.
* [`count-then-page-serial`](https://loadwise.mintlify.site/rules/performance/count-then-page-serial) (low): A count and a page query with the same filter run one after the other.
* [`drizzle-last-insert-id`](https://loadwise.mintlify.site/rules/performance/drizzle-last-insert-id) (medium): A MySQL insert is followed by an extra query for its generated ID.
* [`known-reads-awaited-serially`](https://loadwise.mintlify.site/rules/performance/known-reads-awaited-serially) (medium): Two independent reads from a configured parallelReads group are awaited one after the other.
* [`next-server-fetch-waterfall`](https://loadwise.mintlify.site/rules/performance/next-server-fetch-waterfall) (medium): A Next.js Server Component page awaits independent GET requests in sequence.
* [`numeric-sort-for-extreme`](https://loadwise.mintlify.site/rules/performance/numeric-sort-for-extreme) (low): A numeric sort is used only to read the smallest or largest value.
* [`prisma-count-for-existence`](https://loadwise.mintlify.site/rules/performance/prisma-count-for-existence) (medium): A Prisma query counts all matches only to check whether any row exists.
* [`promise-combinator-serial-await`](https://loadwise.mintlify.site/rules/performance/promise-combinator-serial-await) (medium): Promise.all receives calls that were already awaited one by one.
* [`repeated-workbook-decode`](https://loadwise.mintlify.site/rules/performance/repeated-workbook-decode) (medium): A workflow decodes the same input with ExcelJS more than once.
* [`typeorm-unused-count`](https://loadwise.mintlify.site/rules/performance/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 the `CREATE 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`](https://loadwise.mintlify.site/rules/performance/index-missing-filter) (high): A query filters on a column that no index leads with.
* [`index-missing-foreign-key`](https://loadwise.mintlify.site/rules/performance/index-missing-foreign-key) (high): A foreign key column in the schema has no index.
* [`index-missing-order`](https://loadwise.mintlify.site/rules/performance/index-missing-order) (medium): A query orders by columns that no index serves in that order.
* [`index-redundant-prefix`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/index-unusable-expression) (high): A function or expression on an indexed column keeps the index from being used.
* [`index-unusable-pattern`](https://loadwise.mintlify.site/rules/performance/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](https://ast-grep.github.io/) 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`](https://loadwise.mintlify.site/rules/performance/csharp-ef-count-materialized) (medium): An EF Core DbSet is materialized solely to count its rows.
* [`csharp-ef-query-in-loop`](https://loadwise.mintlify.site/rules/performance/csharp-ef-query-in-loop) (medium): An EF Core DbSet query executes for each loop key.
* [`csharp-fixed-regex-in-loop`](https://loadwise.mintlify.site/rules/performance/csharp-fixed-regex-in-loop) (medium): A C# Regex with a fixed pattern is constructed inside a loop.
* [`csharp-string-concat-in-loop`](https://loadwise.mintlify.site/rules/performance/csharp-string-concat-in-loop) (medium): String concatenation in a C# loop allocates repeatedly; use StringBuilder.
* [`go-fixed-regexp-in-loop`](https://loadwise.mintlify.site/rules/performance/go-fixed-regexp-in-loop) (medium): A Go regexp with a fixed pattern is compiled inside a loop.
* [`go-sql-query-in-loop`](https://loadwise.mintlify.site/rules/performance/go-sql-query-in-loop) (high): A Go database query executes inside a loop instead of batching.
* [`go-string-concat-in-loop`](https://loadwise.mintlify.site/rules/performance/go-string-concat-in-loop) (medium): String concatenation in a Go loop allocates repeatedly; use strings.Builder.
* [`java-fixed-regex-in-loop`](https://loadwise.mintlify.site/rules/performance/java-fixed-regex-in-loop) (medium): A Java Pattern with a fixed pattern is compiled inside a loop.
* [`java-jdbc-query-in-loop`](https://loadwise.mintlify.site/rules/performance/java-jdbc-query-in-loop) (high): A JDBC query executes inside a Java loop instead of batching.
* [`java-string-concat-in-loop`](https://loadwise.mintlify.site/rules/performance/java-string-concat-in-loop) (medium): String concatenation in a Java loop allocates repeatedly; use StringBuilder.
* [`php-eloquent-query-in-loop`](https://loadwise.mintlify.site/rules/performance/php-eloquent-query-in-loop) (medium): An Eloquent key lookup runs for each PHP foreach item.
* [`python-blocking-sleep-in-async`](https://loadwise.mintlify.site/rules/performance/python-blocking-sleep-in-async) (high): A blocking time.sleep call runs inside a Python async def function.
* [`python-copy-growing-list`](https://loadwise.mintlify.site/rules/performance/python-copy-growing-list) (medium): A Python loop rebuilds a growing list with items = items + \[value].
* [`python-fixed-regex-in-loop`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/python-sync-requests-in-async) (high): A blocking requests HTTP call runs inside a Python async def function.
* [`python-unbounded-comprehension`](https://loadwise.mintlify.site/rules/performance/python-unbounded-comprehension) (medium): A Python list comprehension materializes an unbounded collection in memory.
* [`ruby-active-record-query-in-loop`](https://loadwise.mintlify.site/rules/performance/ruby-active-record-query-in-loop) (medium): A Ruby loop performs one Active Record lookup per item.
* [`rust-clone-in-loop`](https://loadwise.mintlify.site/rules/performance/rust-clone-in-loop) (low): Cloning values inside a Rust loop adds avoidable heap allocations.
* [`rust-fixed-regex-in-loop`](https://loadwise.mintlify.site/rules/performance/rust-fixed-regex-in-loop) (medium): A Rust Regex with a fixed pattern is compiled inside a loop.
* [`rust-format-in-loop`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/duplicate-key-read) (medium): A trace repeats the same key or row read under one parent span.
* [`redis-keys-scan`](https://loadwise.mintlify.site/rules/performance/redis-keys-scan) (high): A trace shows a Redis KEYS command scanning the keyspace.
* [`redis-repeated-read`](https://loadwise.mintlify.site/rules/performance/redis-repeated-read) (medium): A trace shows repeated sibling Redis GET or HGET calls.
* [`repeated-db-span`](https://loadwise.mintlify.site/rules/performance/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`](https://loadwise.mintlify.site/rules/performance/mongo-collection-scan) (high): A MongoDB plan scans many documents for each one it returns.
* [`mongo-deep-skip`](https://loadwise.mintlify.site/rules/performance/mongo-deep-skip) (high): A MongoDB query skips past many documents to return a page.
* [`mongo-disk-sort`](https://loadwise.mintlify.site/rules/performance/mongo-disk-sort) (medium): A MongoDB sort spilled to disk.
* [`pg-deep-offset`](https://loadwise.mintlify.site/rules/performance/pg-deep-offset) (high): A PostgreSQL plan walks past many rows with OFFSET to return a page.
* [`pg-disk-sort`](https://loadwise.mintlify.site/rules/performance/pg-disk-sort) (medium): A PostgreSQL sort spilled to disk.
* [`pg-sequential-scan`](https://loadwise.mintlify.site/rules/performance/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.

```sh theme={null}
npx loadwise perf db --env-file .env.staging --schema-snapshot snapshot.json
npx loadwise perf db --queries queries.sql --analyze
npx loadwise perf --schema snapshot.json
```

| Flag | Effect |
| - | - |
| `--schema-snapshot FILE` | Write a schema snapshot (indexes, table sizes, measured round trip) for `--schema`. |
| `--top N` | Explain the N slowest statements (default 20). |
| `--queries FILE` | Explain these concrete SELECT statements. |
| `--analyze` | Run `EXPLAIN ANALYZE` on the `--queries` SELECTs inside rolled-back read-only transactions. |
| `--measure --i-understand-this-locks-tables` | PostgreSQL staging only. Time each suggested index for `--queries` by building it in a rolled-back transaction. |
| `--runs N` | `EXPLAIN ANALYZE` runs per side for `--measure` (default 5). |

`--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`](https://loadwise.mintlify.site/rules/performance/db-duplicate-index) (low): A database index is covered by another index on the same table.
* [`db-missing-index`](https://loadwise.mintlify.site/rules/performance/db-missing-index) (high): A query plan scans a table that a suggested index would let it seek.
* [`db-seq-scan-heavy-table`](https://loadwise.mintlify.site/rules/performance/db-seq-scan-heavy-table) (high): A large table is read by many sequential scans on the live database.
* [`db-slow-query-plan`](https://loadwise.mintlify.site/rules/performance/db-slow-query-plan) (high): A plan uses full scans or large MySQL filesorts or temporary tables.
* [`db-sqlite-large-scan`](https://loadwise.mintlify.site/rules/performance/db-sqlite-large-scan) (medium): A filtered SQLite query plans an unindexed scan of a large table.
* [`db-unindexed-foreign-key`](https://loadwise.mintlify.site/rules/performance/db-unindexed-foreign-key) (high): A foreign key on the live database has no index that leads with its columns.
* [`db-unused-index`](https://loadwise.mintlify.site/rules/performance/db-unused-index) (low): A database index has not been scanned since statistics were last reset.
* [`mongo-collection-scan-observed`](https://loadwise.mintlify.site/rules/performance/mongo-collection-scan-observed) (high): Profiled MongoDB operations scanned a whole collection.

**Safety.** Sessions and transactions are read-only, with a 5 s statement timeout on PostgreSQL, and only SELECT, INSERT, UPDATE and DELETE can be explained. `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).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.