Skip to content

⚡ Parallelize sequential KV operations in src/index.ts - #11

Merged
catoncat merged 1 commit into
mainfrom
perf-optimize-kv-1836528330768438476
May 24, 2026
Merged

⚡ Parallelize sequential KV operations in src/index.ts#11
catoncat merged 1 commit into
mainfrom
perf-optimize-kv-1836528330768438476

Conversation

@catoncat

@catoncat catoncat commented May 24, 2026

Copy link
Copy Markdown
Owner

⚡ Performance Optimization: Parallelize sequential KV operations

💡 What:

Optimized Cloudflare KV storage operations in src/index.ts by replacing sequential await calls with Promise.all. This change affects:

  • handleCreate: Concurrent write of content and metadata.
  • handleEdit: Concurrent write of updated content and metadata.
  • handleAbuseReport: Concurrent update of abuse counter and deduplication key.
  • handleSubdomain: Concurrent fetch of metadata and content for both the /edit view and standard note serving.

🎯 Why:

Sequential asynchronous I/O operations like env.NOTES.put or env.NOTES.get block the execution of the Worker handler until each completes. By parallelizing independent operations, we leverage the asynchronous nature of the environment to perform these tasks concurrently, significantly reducing the "wall-clock" time spent on I/O and thus improving the overall responsiveness of the service.

📊 Measured Improvement:

Establishment of a baseline and post-change measurement was attempted via test/perf.test.ts. However, due to the current environment configuration (missing vitest binary and network restrictions preventing npm install), the tests could not be executed. Despite this, parallelizing I/O is a standard and highly effective optimization for Cloudflare Workers, typically yielding a latency reduction roughly equal to the time of the slowest parallelized call, effectively halving the I/O wait time in cases where two sequential calls were converted to parallel ones.


PR created automatically by Jules for task 1836528330768438476 started by @catoncat


Summary by cubic

Parallelized Cloudflare KV reads/writes in src/index.ts using Promise.all to cut I/O wait time and speed up handlers. This reduces latency for create/edit flows, edit view loads, standard note serving, and abuse report processing.

  • Refactors

    • Replaced sequential env.NOTES.get/put calls with Promise.all in handleCreate, handleEdit, handleAbuseReport, and subdomain paths.
    • Fetch and write content + metadata concurrently, respecting existing TTL options.
  • New Features

    • Added perf baseline harness in test/perf.test.ts using vitest.

Written for commit 0b24d8f. Summary will update on new commits. Review in cubic

Refactor handleCreate, handleEdit, handleAbuseReport, and handleSubdomain to use Promise.all for independent KV operations. This reduces overall handler latency.

Co-authored-by: catoncat <204556023+catoncat@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@catoncat
catoncat merged commit 14fd82e into main May 24, 2026
1 of 2 checks passed
@catoncat
catoncat deleted the perf-optimize-kv-1836528330768438476 branch May 24, 2026 13:02
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