Skip to content

perf(analytics): parallelize KV reads in getAnalyticsWindow - #26

Merged
blueogin merged 2 commits into
mainfrom
patch/parallelize-analytics-kv-reads
Aug 31, 2026
Merged

blueogin merged 2 commits into
mainfrom
patch/parallelize-analytics-kv-reads

Conversation

@goodbounties-nanoclaw-agent

Copy link
Copy Markdown
Contributor

Fixes #25

Summary

  • Fetch the daily getDaily(date) KV reads in getAnalyticsWindow via 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.
  • Run getGlobal() and getState() concurrently alongside that pool instead of serially after it.
  • Drop the redundant getDaily(currentDate) call — the pool's last entry (the i = 0 day) 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_getLogs against a third-party RPC provider), so a wider pool is safe.

Test plan

  • yarn typecheck
  • yarn test (76 passed, including existing getAnalyticsWindow coverage)
  • yarn lint

…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)
Copilot AI lite review requested due to automatic review settings August 31, 2026 15:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() and getState() concurrently with the daily-record pool via Promise.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
blueogin merged commit 1de3a90 into main Aug 31, 2026
3 checks passed
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.

Parallelize KV reads in getAnalyticsWindow for long windows

2 participants