Skip to content
MLReps

Optimize

The query your code runs once per item.

A loop over forty rows that asks the database something inside it is one of the few performance problems that is both obvious in hindsight and invisible in review. MLReps finds it in your code, counts it in the requests you actually served, and shows you the two beside each other.

What it finds in the code

Two rules, and they are the only two. Both are written to be believed rather than to be many: a call counts as a query only against a model your own schema declares, and as being in a loop only when it sits in the body of a loop over a collection of items. Neither is guessed from a name.

query-in-loop
a database call inside a loop over a list — one query per item, every time that code runs
unbounded-query
a read with no limit on it — harmless at a thousand rows, an incident at a million

And what it refuses to call a problem

Read across four open-source applications before this rule was allowed to report anything:

  • A loop that pages, walks or batches — while (hasMore), a step of BATCH_SIZE, a loop over chunks. Batching is the fix this rule would recommend.
  • A loop over a list written in the code. Two items is two queries and always will be.
  • Seeds, scripts and migrations. A backfill that runs once a quarter is not a request somebody is waiting on.

A miss costs one unreported loop. A false report teaches somebody to ignore the whole screen, which costs all of them.

What it does not do yet

This is the newest thing in the product, and the page would rather be short than flattering about it.

  • The two rules read Prisma, Drizzle, Sequelize, TypeORM in TypeScript, and Django and SQLAlchemy in Python. Only those. Another ORM gets no findings, not a clean result.
  • A repository whose checks could not run reads not measured. It is never scored as clean.
  • There is no CPU profiling, no memory analysis and no bundle-size work here. Those are real optimisation and this does not do them.

Start in a terminal

One command, in the repository you want read. On the command line, your source never leaves your machine; the report is uploaded so you can open and share it.

mlreps setup

What that command does →

A finding is not advice

It names the loop, the file and the line, and the operations that loop runs. What to do about it is yours — we produce a patch, you apply it, your tests run it, and you commit it under your name.

The rest of the picture

The same scan draws the architecture, what a change will touch before you merge, and what it could not read.

What fast-written code leaves behind →

Everything on this page is a mechanism rather than a promise. Where a number is a floor it says so, and where a check could not run the screen says that instead of showing you a clean result — how that is held.