Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
Workflow: Investigate Performance
For "X is slow" when the bottleneck is unknown.
Do not optimize before phase 3. An unmeasured optimization that costs readability is a net loss — see .ai/principles.md.
Phase 1 — Define the problem
- What exactly is slow: a page, an admin grid, a scheduled task, an API endpoint, the whole site?
- How slow, and compared to what: a number, or "it used to be fast" with a version.
- Under what conditions: catalog size, order volume, number of stores, concurrent users, cold or warm cache.
- Is it constant, or does it degrade with data volume? Degrading with volume points at a query; constant points at a per-request cost.
- Is it one store or all? One instance or all?
Gate: you have a specific, repeatable slow operation, not a general complaint.
Phase 2 — Measure
- Reproduce with a realistic dataset. Ten products prove nothing; the problems appear at tens of thousands.
- Measure the whole operation before measuring parts.
- Narrow by layer, in this order — the answer is usually found before the last:
- Query count. Is a query running inside a loop? This is the most common cause by a wide margin.
- Query shape. Unbounded result set, missing index, filtering or paging after materialization.
- Cache. Is the path cached at all? Is the key so specific it never hits? Is something clearing the prefix on every request?
- Render. A view component invoked per item, a service call from a view, view-model preparation inside a loop.
- External calls. A blocking HTTP call on the render path.
- Allocation. Large collections copied repeatedly, string building in a loop.
- Compare warm-cache against cold-cache timings — a large gap means the problem is upstream of the cache; no gap means the cache is not working.
Gate: you can name the specific operation consuming the time, with a number. "Probably the database" is not a measurement.
Phase 3 — Explain before fixing
- State why it is slow, mechanically: N products → N queries → N round trips.
- Predict the improvement the fix should produce.
- Check the cause is not a correctness bug in disguise — a cache key missing a store id both leaks data and destroys the hit rate. If so, switch to
fix-bug.md; the leak is the more serious finding.
Gate: the explanation predicts the measurement you already took.
Phase 4 — Choose the fix
In order of preference:
- Remove the work. Do not query what is not displayed. Do not compute what is not used.
- Batch it. One query for the set instead of one per item.
- Push it into the query. Filter, sort, and page in the database.
- Cache it — if it is read far more than written, and the key can carry every result-changing variable. See
.ai/knowledge/caching.md. A cache is a commitment to invalidate correctly, not a free win. - Add an index to support the query shape.
- Move it out of the request to a scheduled task.
- Micro-optimize — last, and only with a measurement.
Reject any fix that trades correctness for speed: dropping a scope filter, caching under a key that omits the store, or serving stale data by skipping invalidation.
Gate: the fix does not weaken any boundary in .ai/knowledge/scoping.md.
Phase 5 — Apply and re-measure
- Apply one change at a time.
- Re-measure after each. A change that does not move the number gets reverted, not kept "because it should help".
- If caching was added: verify invalidation on every write path including delete, and verify the key contains store id and language id where relevant.
- Verify correctness has not moved: same output, same data, across two stores and two languages.
- Run
.ai/checklists/performance.mdand.ai/checklists/definition-of-done.md.
Gate: before and after numbers, from the same dataset.
Phase 6 — Report
- Operation: what was measured.
- Dataset: size and shape — the numbers are meaningless without it.
- Before / after: measured, not estimated.
- Cause: the mechanical explanation.
- Fix: what changed, and which alternatives were rejected.
- Correctness: how you verified output is unchanged, and across which boundaries.
- Invalidation: if caching was added, every write path that clears it.
- Remaining: what is still slow, and what was not measured.