convex-cost

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<!-- GENERATED from convex-agents content/capabilities/convex-cost.json — do not edit by hand. -->
<!-- 由 convex-agents content/capabilities/convex-cost.json 生成——请勿手动编辑。 -->

Preview what this app will cost

预览此应用的成本

Cost surprises come from a handful of functions reading far more data than anyone realized — the same read-heavy patterns convex-advisor flags for perf, seen through the money lens. This capability makes spend legible: it reads the deployment's own bytes/documents-read evidence, attributes it to the functions driving it, projects how it grows with traffic, and names the cheapest fix. It also carries the confirm-cost discipline (Supabase's structural consent for paid actions): before anything metered, state the price and get an explicit yes.
成本意外通常来自少数几个读取数据量远超预期的函数——这些正是 convex-advisor 针对性能问题标记的同一批读取密集型模式,只是这里从成本角度来观察。该能力让支出变得清晰可辨:它会读取部署自身的 bytes/documents-read 证据,将成本归因到相应函数,预测成本如何随流量增长,并找出成本最低的修复方案。它还遵循 confirm-cost 规范(Supabase 针对付费操作的结构化同意机制):对于任何计费操作,都要先说明价格并获得明确同意。

Workflow

工作流

  1. GUARD: deploy-guard — a cost read is read-only over dev/prod (insights is cloud+user-auth only; not previews). Announce the deployment.
  2. GATHER the spend evidence via the official MCP:
    insights
    for the bytes-read / documents-read events (the direct cost signal — Convex bills on function calls + bandwidth),
    tables
    for row counts (a table's size bounds its scan cost),
    functionSpec
    for the surface. If there's no usage/traffic yet, say so and estimate from the query SHAPES instead (a
    .collect()
    on a table projected to grow is a future cost even with zero traffic today).
  3. ATTRIBUTE: rank functions by bytes/documents read per call × observed (or asked-about) call volume — the product is the cost driver, not either alone. A cheap-per-call function called constantly can outweigh an expensive rare one; show both factors.
  4. PROJECT: state how the top drivers scale — a full-table
    .collect()
    grows LINEARLY with the table (cost compounds as data accumulates); an indexed
    .take(n)
    stays flat. Give the user the shape of the curve ('this is O(table size) per call — fine at 1k rows, a bill at 1M'), not a false-precision dollar figure.
  5. NAME THE CHEAPEST FIX per driver — index +
    .withIndex
    instead of scan,
    .paginate
    /
    .take
    instead of
    .collect
    , an aggregate component for counts, caching a hot read — and emit it as a cost-class finding on the bus (evidence: the insight event + the projected growth) pointing at convex-expert/convex-advisor for the actual change.
  6. CONFIRM-COST for paid actions: if the flow includes anything metered (a domain purchase, cloud provisioning, a plan change), STATE the price and recurrence explicitly and get an explicit yes BEFORE proceeding — never let a paid action happen as a side effect (the cost-confirm gate).
  7. REPORT: the current cost drivers ranked, each with its evidence + growth shape + fix, and a plain bottom line ('your spend is dominated by messages:list reading the whole table every call; index it and it drops ~100x'). Honest precision: Convex pricing changes and depends on plan — give relative/shape guidance and cite the pricing page for absolute numbers rather than inventing a dollar total.
  1. 守卫:deploy-guard —— 对 dev/prod 的成本读取是只读操作(insights 仅支持 cloud+user-auth,不支持 previews)。说明正在检查的部署。
  2. 收集:通过官方 MCP 收集支出证据:使用
    insights
    获取 bytes-read / documents-read 事件(直接成本信号——Convex 按函数调用次数 + 带宽计费),使用
    tables
    获取行数(表的大小决定其扫描成本上限),使用
    functionSpec
    获取函数接口。如果目前尚无使用量/流量,应明确说明,并改为根据查询形态进行估算(对一个预计会增长的表执行
    .collect()
    ,即使当前流量为零,也意味着未来成本)。
  3. 归因:按每次调用的 bytes/documents-read × 实际观测到(或所询问的)调用量对函数进行排名——成本驱动因素是二者的乘积,而不是其中任何一个单独因素。一个单次调用成本低但调用频繁的函数,费用可能超过一个单次成本高但不常调用的函数;必须同时展示这两个因素。
  4. 预测:说明主要成本驱动因素如何扩展——对整张表执行
    .collect()
    会随表呈线性增长(随着数据不断累积,成本会复利式增加);使用索引的
    .take(n)
    则保持成本稳定。向用户说明曲线形态('这是每次调用 O(table size)——1k 行时没问题,1M 行时就会产生高额账单'),不要给出看似精确的美元数字。
  5. 找出最低成本的修复方案:针对每个成本驱动因素——使用索引 +
    .withIndex
    代替扫描,使用
    .paginate
    /
    .take
    代替
    .collect
    ,使用聚合组件进行计数,缓存热点读取——并将其作为 cost-class finding 发送到 bus(证据:insight 事件 + 预测的增长趋势),指向 convex-expert/convex-advisor 以执行实际变更。
  6. CONFIRM-COST:如果流程包含任何计费项(域名购买、云资源配置、套餐变更),请明确说明价格和收费周期,并在继续之前获得明确的 yes——绝不能让付费操作作为副作用发生(cost-confirm gate)。
  7. 报告:按排名列出当前的成本驱动因素,每个因素附上证据 + 增长形态 + 修复方案,并给出直白结论('你的支出主要由 messages:list 主导:它每次调用都读取整张表;建立索引后,成本可降至约 1/100')。在精度上保持诚实:Convex 的定价会变化,并且取决于套餐——绝对数字应引用定价页面,而不要臆造一个美元总额。

Rules

规则

  • Cost = data-read-per-call × call-volume — always show both factors; a cheap function called constantly can cost more than an expensive rare one.
  • Read the deployment's own insights/bytes-read evidence for spend; with no traffic yet, price the query SHAPES (a scan on a growing table is a future cost).
  • Give the growth CURVE, not false-precision dollars: O(table) scans compound as data accumulates; indexed access stays flat. Cite the pricing page for absolute figures.
  • Every cost driver names its cheapest fix and emits a cost-class finding on the bus pointing at the fixer (convex-expert/advisor).
  • Confirm-cost for any metered/paid action: state the price + recurrence and get an explicit yes BEFORE it happens — never as a side effect.
  • Read-only over dev/prod (deploy-guard); insights is cloud+user-auth only. Cost composes convex-advisor's evidence but frames it as money, not latency.
  • 成本 = 每次调用的数据读取量 × 调用量——始终同时展示两个因素;一个单次调用成本低但调用频繁的函数,费用可能超过一个单次成本高但不常调用的函数。
  • 使用部署自身的 insights/bytes-read 证据衡量支出;如果还没有流量,则根据查询形态估算成本(对不断增长的表执行扫描,即使当前流量为零,也意味着未来成本)。
  • 给出增长曲线,而不是看似精确的美元数字:O(table) 扫描的成本会随着数据累积而复利式增长;索引访问则保持稳定。绝对数字应引用定价页面。
  • 每个成本驱动因素都要给出成本最低的修复方案,并作为 cost-class finding 发送到 bus,指向修复方(convex-expert/advisor)。
  • 对任何计费/付费操作执行 confirm-cost:在操作发生前说明价格 + 收费周期并获得明确的 yes——绝不能作为副作用执行。
  • 对 dev/prod 执行只读操作(deploy-guard);insights 仅支持 cloud+user-auth。成本分析会复用 convex-advisor 的证据,但将其置于成本而非延迟的视角下。