When is a performance problem an architecture signal?
A slow database operation can reveal that set-based work belongs in the database rather than in an application loop.
A performance problem is an architecture signal when the database can handle a batch the application is processing one row at a time.
Relational databases are designed to operate on sets. Moving data across the application boundary one row at a time can add repeated network calls, transaction overhead, and unnecessary coordination.
My view: check where the loop belongs before trying to reduce allocations, parallelize it, or add caching.
Measure the shape of the work
Before changing code, identify:
- How many database round trips occur?
- Is the transaction larger than it needs to be?
- Does each iteration repeat the same planning or lookup work?
- Can the database express the operation as a single update, join, or deletion?
- What locking behavior does the current approach create?
Set-based does not mean careless
A set-based query, which works on rows together, can be much faster, but it still needs clear behavior, appropriate indexes, predictable locking, and tests against realistic data.
My view: aim for faster code and a clear place for the work to happen, not just a passing benchmark.