Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Audit and fix Convex performance issues: hot reads, OCC conflicts, subscription cost, and function limits.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: convex-performance-audit3description:4Audits Convex performance for reads, subscriptions, write contention, and5function limits. Use for slow features, insights findings, OCC conflicts, or6read amplification.7---89# Convex Performance Audit1011Diagnose and fix performance problems in Convex applications, one problem class12at a time.1314## When to Use1516- A Convex page or feature feels slow or expensive17- `npx convex insights --details` reports high bytes read, documents read, or18OCC conflicts19- Low-freshness read paths are using reactivity where point-in-time reads would20do21- OCC conflict errors or excessive mutation retries22- High subscription count or slow UI updates23- Functions approaching execution or transaction limits24- The same performance pattern needs fixing across sibling functions2526## When Not to Use2728- Initial Convex setup, auth setup, or component extraction29- Pure schema migrations with no performance goal30- One-off micro-optimizations without a user-visible or deployment-visible31problem3233## Guardrails3435- Prefer simpler code when scale is small, traffic is modest, or the available36signals are weak37- Do not recommend digest tables, document splitting, fetch-strategy changes, or38migration-heavy rollouts unless there is a measured signal, a clearly39unbounded path, or a known hot read/write path40- In Convex, a simple scan on a small table is often acceptable. Do not invent41structural work just because a pattern is not ideal at large scale4243## First Step: Gather Signals4445Start with the strongest signal available:46471. If deployment Health insights are already available from the user or the48current context, treat them as a first-class source of performance signals.492. If CLI insights are available, run `npx convex insights --details`. Use50`--prod`, `--preview-name`, or `--deployment-name` when needed.51- If the local repo's Convex CLI is too old to support `insights`, try52`npx -y convex@latest insights --details` before giving up.533. If the repo already uses `convex-doctor`, you may treat its findings as54hints. Do not require it, and do not treat it as the source of truth.554. If runtime signals are unavailable, audit from code anyway, but keep the56guardrails above in mind. Lack of insights is not proof of health, but it is57also not proof that a large refactor is warranted.5859## Signal Routing6061After gathering signals, identify the problem class and read the matching62reference file.6364| Signal | Reference |65| -------------------------------------------------------------- | ----------------------------------------- |66| High bytes or documents read, JS filtering, unnecessary joins | `references/hot-path-rules.md` |67| OCC conflict errors, write contention, mutation retries | `references/occ-conflicts.md` |68| High subscription count, slow UI updates, excessive re-renders | `references/subscription-cost.md` |69| Function timeouts, transaction size errors, large payloads | `references/function-budget.md` |70| General "it's slow" with no specific signal | Start with `references/hot-path-rules.md` |7172Multiple problem classes can overlap. Read the most relevant reference first,73then check the others if symptoms remain.7475## Escalate Larger Fixes7677If the likely fix is invasive, cross-cutting, or migration-heavy, stop and78present options before editing.7980Examples:8182- introducing digest or summary tables across multiple flows83- splitting documents to isolate frequently-updated fields84- reworking pagination or fetch strategy across several screens85- switching to a new index or denormalized field that needs migration-safe86rollout8788When correctness depends on handling old and new states during a rollout,89consult `skills/convex-migration-helper/SKILL.md` for the migration workflow.9091## Workflow9293### 1. Scope the problem9495Pick one concrete user flow from the actual project. Look at the codebase,96client pages, and API surface to find the flow that matches the symptom.9798Write down:99100- entrypoint functions101- client callsites using `useQuery`, `usePaginatedQuery`, or `useMutation`102- tables read103- tables written104- whether the path is high-read, high-write, or both105106### 2. Trace the full read and write set107108For each function in the path:1091101. Trace every `ctx.db.get()` and `ctx.db.query()`1112. Trace every `ctx.db.patch()`, `ctx.db.replace()`, and `ctx.db.insert()`1123. Note foreign-key lookups, JS-side filtering, and full-document reads1134. Identify all sibling functions touching the same tables1145. Identify reactive stats, aggregates, or widgets rendered on the same page115116In Convex, every extra read increases transaction work, and every write can117invalidate reactive subscribers. Treat read amplification and invalidation118amplification as first-class problems.119120### 3. Apply fixes from the relevant reference121122Read the reference file matching your problem class. Each reference includes123specific patterns, code examples, and a recommended fix order.124125Do not stop at the single function named by an insight. Trace sibling readers126and writers touching the same tables.127128### 4. Fix sibling functions together129130When one function touching a table has a performance bug, audit sibling131functions for the same pattern.132133After finding one problem, inspect both sibling readers and sibling writers for134the same table family, including companion digest or summary tables.135136Examples:137138- If one list query switches from full docs to a digest table, inspect the other139list queries for that table140- If one mutation isolates a frequently-updated field or splits a hot document,141inspect the other writers to the same table142- If one read path needs a migration-safe rollout for an unbackfilled field,143inspect sibling reads for the same rollout risk144145Do not leave one path fixed and another path on the old pattern unless there is146a clear product reason.147148### 5. Verify before finishing149150Confirm all of these:1511521. Results are the same as before, no dropped records1532. Eliminated reads or writes are no longer in the path where expected1543. Fallback behavior works when denormalized or indexed fields are missing1554. Frequently-updated fields are isolated from widely-read documents where156needed1575. Every relevant sibling reader and writer was inspected, not just the original158function159160## Reference Files161162- `references/hot-path-rules.md` - Read amplification, invalidation,163denormalization, indexes, digest tables164- `references/occ-conflicts.md` - Write contention, OCC resolution, hot document165splitting166- `references/subscription-cost.md` - Reactive query cost, subscription167granularity, point-in-time reads168- `references/function-budget.md` - Execution limits, transaction size, large169documents, payload size170171Also check the official172[Convex Best Practices](https://docs.convex.dev/understanding/best-practices/)173page for additional patterns covering argument validation, access control, and174code organization that may surface during the audit.175176## Checklist177178- [ ] Gathered signals from insights, dashboard, or code audit179- [ ] Identified the problem class and read the matching reference180- [ ] Scoped one concrete user flow or function path181- [ ] Traced every read and write in that path182- [ ] Identified sibling functions touching the same tables183- [ ] Applied fixes from the reference, following the recommended fix order184- [ ] Fixed sibling functions consistently185- [ ] Verified behavior and confirmed no regressions186