Skip to content

perf(homepage): aggregate strips in SQL#72

Merged
VrianCao merged 1 commit intomasterfrom
perf/homepage-aggregate-strips
Apr 14, 2026
Merged

perf(homepage): aggregate strips in SQL#72
VrianCao merged 1 commit intomasterfrom
perf/homepage-aggregate-strips

Conversation

@VrianCao
Copy link
Copy Markdown
Owner

Why

Current dominant CPU outlier is the homepage snapshot refresh (fetch /api/v1/internal/refresh/homepage) at ~13–16ms CPU per invocation.

A big part of that path is materializing heartbeat + uptime strip arrays in JS (looping over many rows) after reading check_results and monitor_daily_rollups.

What

  • Change computePublicHomepagePayload() to fetch pre-aggregated strips from D1:
    • Heartbeat strip: checked_at[], latency_ms[], status_codes via json_group_array(...) + group_concat(...)
    • Uptime day strip: day_start_at[], downtime_sec[], unknown_sec[], uptime_pct_milli[] via json_group_array(...), plus rollup total sums for uptime_30d
  • JS now assigns the arrays directly (with safe JSON parsing) and only appends the optional “today” partial bucket.

No API shape changes.

Where

  • apps/worker/src/public/homepage.ts
  • apps/worker/test/public-homepage-compute.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
      • Watch cpuTime for fetch /api/v1/internal/refresh/homepage (expected drop)

@VrianCao VrianCao merged commit a06d5ad into master Apr 14, 2026
4 checks passed
@VrianCao VrianCao deleted the perf/homepage-aggregate-strips branch April 14, 2026 11:16
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