perf(scheduler): refresh homepage snapshot inline#70
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Workers Tail shows
fetch /api/v1/internal/refresh/homepageis the dominant >10ms CPU path (and can spike much higher on cold starts). This internal refresh is currently triggered once per scheduled tick viaenv.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
env.SELF.fetch()to trigger homepage snapshot refresh.ctx.waitUntil(...)) inside the scheduled tick, usingrefreshPublicHomepageSnapshotIfNeeded.This removes the extra
fetch /api/v1/internal/refresh/homepageinvocation entirely.Trade-off
Where
apps/worker/src/scheduler/scheduled.tsapps/worker/test/scheduled.test.tsHow to verify
Local:
pnpm --filter @uptimer/worker lintpnpm --filter @uptimer/worker typecheckpnpm --filter @uptimer/worker testProd (after deploy):
pnpm --filter @uptimer/worker exec wrangler tail uptimer --format json --sampling-rate 0.999fetch /api/v1/internal/refresh/homepagedisappearsscheduled * * * * *cpuTimestays <=10ms