Skip to content

perf(web): load Infra auto top-up only when a transcript charge needs it - #4197

Merged
richiemcilroy merged 3 commits into
mainfrom
perf/workflow-lazy-auto-top-up
Nov 13, 2026
Merged

richiemcilroy merged 3 commits into
mainfrom
perf/workflow-lazy-auto-top-up

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Every workflow step ships in one bundle, so a module imported by one step is loaded by all of them on a cold start. Since #4156, lib/developer-transcript-billing.ts (reached from workflows/developer-transcribe.ts) has imported scheduleAutoTopUp statically. That pulls lib/infra-auto-top-up.ts into the bundle, and with it Stripe, Resend and the React Email templates. Regular transcription, processing and AI generation steps now load all three on every cold start, even though only Infra transcript charges use them.

This PR loads the auto top-up module on first use in that one file, the way lib/infra-storage-minimum.ts already does. Behaviour is unchanged: the function and its arguments are the same, and it is still awaited at the same three call sites.

Measurement

I built all 16 "use step" workflow files with esbuild (minified, ESM, code splitting) and summed only the code reachable through static imports from the entry files:

main (e19d546) this PR
Static step graph, minified 6,488,939 B 5,922,012 B
stripe 94,320 B 0
@react-email/* 381,130 B 0
resend 8,208 B 0
lib/infra-auto-top-up.ts 16,661 B 0 (own chunk, loaded on first use)

With this change, the only imports of lib/infra-auto-top-up.ts from step code are dynamic ones. Loading Stripe, Resend and React Email unbundled took about 150 ms per cold process on a laptop, so that much comes off every workflow cold start.

Testing

  • CI runs the full web unit suite.
  • biome check is clean on the changed file.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable regression was found.

Summary

Defers loading infra-auto-top-up.ts until transcript billing calls scheduleAutoTopUp, keeping its heavy dependencies out of the static import path.

  • Workflow steps load auto top-up only when transcript billing needs it.

Reviews (2) · Last reviewed commit: "style(web): sort the auto top-up type im..." · Reviewed by Greptile

@sandchest-com

sandchest-com Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Sandchest

Sandchest reviewed 2b984c1: nothing exploitable found in this change.

Sandchest reviews every change for vulnerabilities an attacker could use · 4 credits · Review details

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

Open in Capy

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 13, 2026 11:23 Inactive
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Nov 13, 2026 11:26am UTC

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 13, 2026 11:26 Inactive

@capy-ai capy-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capy found no issues.

View 1 other finding in Capy.

Open in Capy

@richiemcilroy

Copy link
Copy Markdown
Member Author

hey @greptileai, please re-review the PR

@richiemcilroy
richiemcilroy merged commit 33c5825 into main Nov 13, 2026
40 checks passed

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cap-web — 2b984c17 Deployed Nov 13, 2026 by vercel[bot]
Preview – cap-status — 2b984c17 Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant