Inside a real engineering workflow that turned performance data into small fixes—and millions fewer database calls.

By Ashu Kumar

Published: 2026-11-11

URL: https://theagenticstack.substack.com/p/your-app-is-slow-can-an-ai-agent


Sentry was asking its database for information the application already had.

An estimated 143 million times a week.

The individual lookup was quick: around 1.3 milliseconds at the median. The code retrieved a project record, passed it along, and continued processing. Nothing about that small operation looked especially dramatic.

Except the same project was already available on the event being processed.

The fix reused that existing object. You can read the explanation in the merged pull request.

That is a compelling assignment for an AI agent: find the tiny piece of unnecessary work that becomes expensive through repetition.

Picture the performance ticket in your own backlog. A report takes too long to open. Saving a record feels sluggish. Someone suggests adding a cache, but nobody has established what the application is waiting for.

“Make this faster” leaves an engineer with a substantial investigation before there is anything useful to change.

A recent Sentry engineering account shows how a coding agent can help with that investigation.

On November 3, engineer Scott Cooper described connecting Claude Opus 5.5 to Sentry’s own performance data through its MCP server. The agent examined frequently executed operations and their duration, then returned candidates with source locations, estimated volumes, and example traces. Cooper chose what to pursue and reviewed the proposed changes.

That gives the agent a much more specific job than reading a repository and suggesting optimizations.

A repository shows how the software is written. A trace follows what happened during an actual request: which database calls ran, which services were contacted, and where time accumulated. Together, they let an investigator connect an expensive operation to the code responsible for it.

A perfectly ordinary line can become worth investigating when the application executes it millions of times.

The project lookup illustrates this neatly. Recognizing that an object can be reused is familiar engineering work. Establishing where that opportunity exists, confirming that it is the same object, and discovering how frequently the extra lookup happens takes investigation.

That combination makes the finding useful. A reviewer gets a specific change with a reason to prioritize it.

Another Sentry fix caught a different kind of wasted effort.

A function checked a cache and queried the database for an association before establishing whether the current case could require that association at all. For certain groups, the answer was already available: there was nothing to create.

Missing associations were not cached, so subsequent occurrences repeated the unsuccessful search.

The pull request describing the change estimated approximately 127 million database lookups a week. Moving the eligibility check ahead of the lookup let those cases return earlier.

Both fixes are easy to understand once someone points them out. That is precisely their appeal. The application did not need a new architecture to avoid those particular calls.

It needed someone to follow the execution path closely enough to ask why they happened.

There is also a useful correction to the usual “AI made everything faster” story.

A separate repository-listing change addressed an endpoint that filtered repositories by organization and status, then sorted them by name. Without an index matching that access pattern, each page involved reading and sorting more records than necessary.

The team added an index covering those fields.

Cooper subsequently reported that average database execution for the query fell from roughly 30 milliseconds to 9.2 milliseconds. However, the requests were not consistently faster.

That detail deserves to survive the headline.

A database operation can become cheaper while the person using the application still waits elsewhere in the request. A useful performance investigation therefore needs to distinguish the work removed from the improvement the user actually experiences.

Sentry’s query-volume figures are estimates based on sampled traffic. They give the fixes scale; they are not an independently audited measure of AI productivity.

For your own application, the first experiment can be much smaller.

Choose one flow people already complain about: opening an account page, loading a report, or saving a record. Record its current behavior, including slower requests and the number of database calls involved. That gives the investigation a starting point and any proposed fix a comparison.

Then give the agent access to the relevant repository and performance data, with read-only permissions for the investigation.

Here is a starting brief I would use:

Investigate unnecessary database work in this endpoint during the selected time window.
Return up to three candidates. For each, include an example trace, the relevant file and line, how frequently the operation executes, and why it may be avoidable.
Mark sampled estimates and missing information clearly. Recommend the smallest change for the strongest candidate, explain what behavior it could affect, and describe how we should validate it.
Keep this pass to investigation.

This produces something a developer can act on. “Add caching” becomes a claim about a particular operation, backed by a particular request.

The next step is to challenge that claim.

If the agent proposes reusing an object, establish that it represents the same record and has the required freshness. If it proposes skipping a lookup, identify the cases that still need it. If it proposes an index, examine the query plan and the operational cost of introducing and maintaining that index.

For SQL changes, PostgreSQL’s EXPLAIN ANALYZE can expose actual execution behavior, including row counts and repeated operations. It also executes the statement. Use an approved test environment or database mirror, and remember that a fast result with cached data may differ from a cold run.

The important question is whether the changed query still returns the required result while doing less work under relevant conditions.

After a reviewed change ships, return to the original flow. Compare query counts, database work, and request latency under comparable traffic. Check the slower end of the latency distribution too; an average can conceal the requests that make the application frustrating.

If the database improvement does not reach the user, the investigation has another lead to follow.

This is the kind of agent workflow I find interesting because it starts with an existing product problem and ends with something inspectable: a small change, a measured result, and a clearer understanding of the application.

The first assignment does not need to span the whole codebase. Give the agent the performance ticket your team has already postponed twice.

There may be a very fast little query hiding inside it—and far too many copies of that query running every week.


References

  1. Sentry — Finding performance wins in our own traces with a coding agent

Scott Cooper’s November 3 account of the workflow, reported results, and measurement limits.

  1. Sentry PR #127494 — Reuse an existing project object

The change associated with an estimated 143 million unnecessary project lookups per week.

  1. Sentry PR #127495 — Check whether an association is needed before looking it up

The early-return change associated with an estimated 127 million weekly lookups.

  1. Sentry PR #128052 — Index the repository-listing access pattern

The query pattern, index design, and deployment considerations.

  1. PostgreSQL documentation — Using EXPLAIN

How to inspect query plans, interpret actual execution statistics, and account for measurement limitations.