Skip to content

perf(scheduler): refresh homepage snapshot inline#70

Merged
VrianCao merged 1 commit intomasterfrom
perf/inline-homepage-refresh
Apr 14, 2026
Merged

perf(scheduler): refresh homepage snapshot inline#70
VrianCao merged 1 commit intomasterfrom
perf/inline-homepage-refresh

Conversation

@VrianCao
Copy link
Copy Markdown
Owner

Why

Workers Tail shows fetch /api/v1/internal/refresh/homepage is the dominant >10ms CPU path (and can spike much higher on cold starts). This internal refresh is currently triggered once per scheduled tick via env.SELF.fetch(...), which creates an extra fetch invocation and pays an extra cold-start / module-init tax.

Given the 10ms CPU budget, a separate self-invocation is expensive: it’s an additional invocation that must also fit under the CPU limit.

What

  • Stop using env.SELF.fetch() to trigger homepage snapshot refresh.
  • Refresh the homepage snapshot inline (still in ctx.waitUntil(...)) inside the scheduled tick, using refreshPublicHomepageSnapshotIfNeeded.

This removes the extra fetch /api/v1/internal/refresh/homepage invocation entirely.

Trade-off

  • Scheduled tick CPU will increase (it now also runs homepage refresh work). The goal is that the single scheduled invocation remains <=10ms CPU while removing the extra >10ms fetch invocation.

Where

  • apps/worker/src/scheduler/scheduled.ts
  • apps/worker/test/scheduled.test.ts

How to verify

  • Local:

    • pnpm --filter @uptimer/worker lint
    • pnpm --filter @uptimer/worker typecheck
    • pnpm --filter @uptimer/worker test
  • Prod (after deploy):

    • pnpm --filter @uptimer/worker exec wrangler tail uptimer --format json --sampling-rate 0.999
      • Confirm fetch /api/v1/internal/refresh/homepage disappears
      • Confirm scheduled * * * * * cpuTime stays <=10ms

@VrianCao VrianCao merged commit 4a545ff into master Apr 14, 2026
4 checks passed
@VrianCao VrianCao deleted the perf/inline-homepage-refresh branch April 14, 2026 10:59
VrianCao added a commit that referenced this pull request Apr 14, 2026
…resh"

This reverts commit 4a545ff, reversing
changes made to 543da3a.
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