perf(analytics): parallelize KV reads in getAnalyticsWindow - #26
Merged
Merged
Conversation
…indow Fetch the daily KV records with a bounded-concurrency worker pool (same cursor-worker pattern as fetchLogsByRange) instead of one sequential round-trip per day, run getGlobal()/getState() alongside that pool instead of serially after it, and drop the redundant getDaily(currentDate) call by reusing the pool last entry. Fixes #25 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> On-Behalf-Of: gdpatchagent[onecli] (yaskkeryodtdijpv)
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the performance of the /analytics window query in the Cloudflare Worker by parallelizing per-day KV reads with bounded concurrency, and overlapping the remaining independent KV reads to reduce wall-clock latency for long windows (up to 365 days).
Changes:
- Adds a bounded-concurrency worker pool (
ANALYTICS_KV_READ_WORKERS = 20) to fetch daily analytics records from KV in parallel. - Runs
getGlobal()andgetState()concurrently with the daily-record pool viaPromise.all. - Removes the redundant
getDaily(currentDate)KV read by reusing the last fetched daily record as “today”.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
blueogin
approved these changes
Aug 31, 2026
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.
Fixes #25
Summary
getDaily(date)KV reads ingetAnalyticsWindowvia a bounded-concurrency worker pool (ANALYTICS_KV_READ_WORKERS = 20), reusing the same cursor-worker pattern already in this file (fetchLogsByRange) instead of adding a dependency.getGlobal()andgetState()concurrently alongside that pool instead of serially after it.getDaily(currentDate)call — the pool's last entry (thei = 0day) is already that record.20 workers were chosen over the RPC log-batch pool's 5 because KV reads have no external rate limit to respect (unlike
eth_getLogsagainst a third-party RPC provider), so a wider pool is safe.Test plan
yarn typecheckyarn test(76 passed, including existinggetAnalyticsWindowcoverage)yarn lint