Convex Performance Audit
Diagnose and fix performance problems in Convex applications, one problem class
at a time.
When to Use
- A Convex page or feature feels slow or expensive
npx convex insights --details reports high bytes read, documents read, or
OCC conflicts
- Low-freshness read paths are using reactivity where point-in-time reads would
do
- OCC conflict errors or excessive mutation retries
- High subscription count or slow UI updates
- Functions approaching execution or transaction limits
- The same performance pattern needs fixing across sibling functions
When Not to Use
- Initial Convex setup, auth setup, or component extraction
- Pure schema migrations with no performance goal
- One-off micro-optimizations without a user-visible or deployment-visible
problem
Guardrails
- Prefer simpler code when scale is small, traffic is modest, or the available
signals are weak
- Do not recommend digest tables, document splitting, fetch-strategy changes, or
migration-heavy rollouts unless there is a measured signal, a clearly
unbounded path, or a known hot read/write path
- In Convex, a simple scan on a small table is often acceptable. Do not invent
structural work just because a pattern is not ideal at large scale
First Step: Gather Signals
Start with the strongest signal available:
- If deployment Health insights are already available from the user or the
current context, treat them as a first-class source of performance signals.
- If CLI insights are available, run
npx convex insights --details. Use
--prod, --preview-name, or --deployment-name when needed.
- If the local repo's Convex CLI is too old to support
insights, try
npx -y convex@latest insights --details before giving up.
- If the repo already uses
convex-doctor, you may treat its findings as
hints. Do not require it, and do not treat it as the source of truth.
- If runtime signals are unavailable, audit from code anyway, but keep the
guardrails above in mind. Lack of insights is not proof of health, but it is
also not proof that a large refactor is warranted.
Signal Routing
After gathering signals, identify the problem class and read the matching
reference file.
| Signal |
Reference |
| High bytes or documents read, JS filtering, unnecessary joins |
references/hot-path-rules.md |
| OCC conflict errors, write contention, mutation retries |
references/occ-conflicts.md |
| High subscription count, slow UI updates, excessive re-renders |
references/subscription-cost.md |
| Function timeouts, transaction size errors, large payloads |
references/function-budget.md |
| General "it's slow" with no specific signal |
Start with references/hot-path-rules.md |
Multiple problem classes can overlap. Read the most relevant reference first,
then check the others if symptoms remain.
Escalate Larger Fixes
If the likely fix is invasive, cross-cutting, or migration-heavy, stop and
present options before editing.
Examples:
- introducing digest or summary tables across multiple flows
- splitting documents to isolate frequently-updated fields
- reworking pagination or fetch strategy across several screens
- switching to a new index or denormalized field that needs migration-safe
rollout
When correctness depends on handling old and new states during a rollout,
consult the convex-migration-helper skill for the migration workflow.
Workflow
1. Scope the problem
Pick one concrete user flow from the actual project. Look at the codebase,
client pages, and API surface to find the flow that matches the symptom.
Write down:
- entrypoint functions
- client callsites using
useQuery, usePaginatedQuery, or useMutation
- tables read
- tables written
- whether the path is high-read, high-write, or both
2. Trace the full read and write set
For each function in the path:
- Trace every
ctx.db.get() and ctx.db.query()
- Trace every
ctx.db.patch(), ctx.db.replace(), and ctx.db.insert()
- Note foreign-key lookups, JS-side filtering, and full-document reads
- Identify all sibling functions touching the same tables
- Identify reactive stats, aggregates, or widgets rendered on the same page
In Convex, every extra read increases transaction work, and every write can
invalidate reactive subscribers. Treat read amplification and invalidation
amplification as first-class problems.
3. Apply fixes from the relevant reference
Read the reference file matching your problem class. Each reference includes
specific patterns, code examples, and a recommended fix order.
Do not stop at the single function named by an insight. Trace sibling readers
and writers touching the same tables.
4. Fix sibling functions together
When one function touching a table has a performance bug, audit sibling
functions for the same pattern.
After finding one problem, inspect both sibling readers and sibling writers for
the same table family, including companion digest or summary tables.
Examples:
- If one list query switches from full docs to a digest table, inspect the other
list queries for that table
- If one mutation isolates a frequently-updated field or splits a hot document,
inspect the other writers to the same table
- If one read path needs a migration-safe rollout for an unbackfilled field,
inspect sibling reads for the same rollout risk
Do not leave one path fixed and another path on the old pattern unless there is
a clear product reason.
5. Verify before finishing
Confirm all of these:
- Results are the same as before, no dropped records
- Eliminated reads or writes are no longer in the path where expected
- Fallback behavior works when denormalized or indexed fields are missing
- Frequently-updated fields are isolated from widely-read documents where
needed
- Every relevant sibling reader and writer was inspected, not just the original
function
Reference Files
references/hot-path-rules.md - Read amplification, invalidation,
denormalization, indexes, digest tables
references/occ-conflicts.md - Write contention, OCC resolution, hot document
splitting
references/subscription-cost.md - Reactive query cost, subscription
granularity, point-in-time reads
references/function-budget.md - Execution limits, transaction size, large
documents, payload size
Also check the official
Convex Best Practices
page for additional patterns covering argument validation, access control, and
code organization that may surface during the audit.
Checklist
1---2name: convex-performance-audit3description: Audits Convex performance for reads, subscriptions, write contention, and function limits. Use for slow features, insights findings, OCC conflicts, or read amplification.4---56# Convex Performance Audit78Diagnose and fix performance problems in Convex applications, one problem class9at a time.1011## When to Use1213- A Convex page or feature feels slow or expensive14- `npx convex insights --details` reports high bytes read, documents read, or15 OCC conflicts16- Low-freshness read paths are using reactivity where point-in-time reads would17 do18- OCC conflict errors or excessive mutation retries19- High subscription count or slow UI updates20- Functions approaching execution or transaction limits21- The same performance pattern needs fixing across sibling functions2223## When Not to Use2425- Initial Convex setup, auth setup, or component extraction26- Pure schema migrations with no performance goal27- One-off micro-optimizations without a user-visible or deployment-visible28 problem2930## Guardrails3132- Prefer simpler code when scale is small, traffic is modest, or the available33 signals are weak34- Do not recommend digest tables, document splitting, fetch-strategy changes, or35 migration-heavy rollouts unless there is a measured signal, a clearly36 unbounded path, or a known hot read/write path37- In Convex, a simple scan on a small table is often acceptable. Do not invent38 structural work just because a pattern is not ideal at large scale3940## First Step: Gather Signals4142Start with the strongest signal available:43441. If deployment Health insights are already available from the user or the45 current context, treat them as a first-class source of performance signals.462. If CLI insights are available, run `npx convex insights --details`. Use47 `--prod`, `--preview-name`, or `--deployment-name` when needed.48 - If the local repo's Convex CLI is too old to support `insights`, try49 `npx -y convex@latest insights --details` before giving up.503. If the repo already uses `convex-doctor`, you may treat its findings as51 hints. Do not require it, and do not treat it as the source of truth.524. If runtime signals are unavailable, audit from code anyway, but keep the53 guardrails above in mind. Lack of insights is not proof of health, but it is54 also not proof that a large refactor is warranted.5556## Signal Routing5758After gathering signals, identify the problem class and read the matching59reference file.6061| Signal | Reference |62| -------------------------------------------------------------- | ----------------------------------------- |63| High bytes or documents read, JS filtering, unnecessary joins | `references/hot-path-rules.md` |64| OCC conflict errors, write contention, mutation retries | `references/occ-conflicts.md` |65| High subscription count, slow UI updates, excessive re-renders | `references/subscription-cost.md` |66| Function timeouts, transaction size errors, large payloads | `references/function-budget.md` |67| General "it's slow" with no specific signal | Start with `references/hot-path-rules.md` |6869Multiple problem classes can overlap. Read the most relevant reference first,70then check the others if symptoms remain.7172## Escalate Larger Fixes7374If the likely fix is invasive, cross-cutting, or migration-heavy, stop and75present options before editing.7677Examples:7879- introducing digest or summary tables across multiple flows80- splitting documents to isolate frequently-updated fields81- reworking pagination or fetch strategy across several screens82- switching to a new index or denormalized field that needs migration-safe83 rollout8485When correctness depends on handling old and new states during a rollout,86consult the `convex-migration-helper` skill for the migration workflow.8788## Workflow8990### 1. Scope the problem9192Pick one concrete user flow from the actual project. Look at the codebase,93client pages, and API surface to find the flow that matches the symptom.9495Write down:9697- entrypoint functions98- client callsites using `useQuery`, `usePaginatedQuery`, or `useMutation`99- tables read100- tables written101- whether the path is high-read, high-write, or both102103### 2. Trace the full read and write set104105For each function in the path:1061071. Trace every `ctx.db.get()` and `ctx.db.query()`1082. Trace every `ctx.db.patch()`, `ctx.db.replace()`, and `ctx.db.insert()`1093. Note foreign-key lookups, JS-side filtering, and full-document reads1104. Identify all sibling functions touching the same tables1115. Identify reactive stats, aggregates, or widgets rendered on the same page112113In Convex, every extra read increases transaction work, and every write can114invalidate reactive subscribers. Treat read amplification and invalidation115amplification as first-class problems.116117### 3. Apply fixes from the relevant reference118119Read the reference file matching your problem class. Each reference includes120specific patterns, code examples, and a recommended fix order.121122Do not stop at the single function named by an insight. Trace sibling readers123and writers touching the same tables.124125### 4. Fix sibling functions together126127When one function touching a table has a performance bug, audit sibling128functions for the same pattern.129130After finding one problem, inspect both sibling readers and sibling writers for131the same table family, including companion digest or summary tables.132133Examples:134135- If one list query switches from full docs to a digest table, inspect the other136 list queries for that table137- If one mutation isolates a frequently-updated field or splits a hot document,138 inspect the other writers to the same table139- If one read path needs a migration-safe rollout for an unbackfilled field,140 inspect sibling reads for the same rollout risk141142Do not leave one path fixed and another path on the old pattern unless there is143a clear product reason.144145### 5. Verify before finishing146147Confirm all of these:1481491. Results are the same as before, no dropped records1502. Eliminated reads or writes are no longer in the path where expected1513. Fallback behavior works when denormalized or indexed fields are missing1524. Frequently-updated fields are isolated from widely-read documents where153 needed1545. Every relevant sibling reader and writer was inspected, not just the original155 function156157## Reference Files158159- `references/hot-path-rules.md` - Read amplification, invalidation,160 denormalization, indexes, digest tables161- `references/occ-conflicts.md` - Write contention, OCC resolution, hot document162 splitting163- `references/subscription-cost.md` - Reactive query cost, subscription164 granularity, point-in-time reads165- `references/function-budget.md` - Execution limits, transaction size, large166 documents, payload size167168Also check the official169[Convex Best Practices](https://docs.convex.dev/understanding/best-practices/)170page for additional patterns covering argument validation, access control, and171code organization that may surface during the audit.172173## Checklist174175- [ ] Gathered signals from insights, dashboard, or code audit176- [ ] Identified the problem class and read the matching reference177- [ ] Scoped one concrete user flow or function path178- [ ] Traced every read and write in that path179- [ ] Identified sibling functions touching the same tables180- [ ] Applied fixes from the reference, following the recommended fix order181- [ ] Fixed sibling functions consistently182- [ ] Verified behavior and confirmed no regressions