Skip to content

⚡ Parallelize KV operations and fix CI workflow - #13

Open
catoncat wants to merge 1 commit into
mainfrom
perf-optimize-kv-1836528330768438476
Open

⚡ Parallelize KV operations and fix CI workflow#13
catoncat wants to merge 1 commit into
mainfrom
perf-optimize-kv-1836528330768438476

Conversation

@catoncat

@catoncat catoncat commented Jun 19, 2026

Copy link
Copy Markdown
Owner

⚡ Performance Optimization & CI Fix

💡 What:

  1. Parallelized KV Operations: Optimized Cloudflare KV storage operations in src/index.ts by replacing sequential await calls with Promise.all.
    • Optimized handleCreate, handleEdit, handleAbuseReport, and handleSubdomain.
    • Both writes and reads are now performed concurrently where possible.
  2. CI Workflow Update: Upgraded the Node.js version in .github/workflows/test.yml from 20 to 22.
  3. Lockfile Synchronization: Synchronized package-lock.json to ensure a clean npm ci in the CI environment.

🎯 Why:

  • Performance: Sequential asynchronous I/O operations block the handler. Parallelizing them reduces total latency, often halving the time spent on I/O for these operations.
  • CI Reliability: The GitHub Actions workflow failed because wrangler and other dependencies now require Node.js >= 22. Additionally, npm ci requires a perfectly synchronized lockfile.

📊 Measured Improvement:

While local test execution was restricted by the environment, parallelizing independent I/O calls is a proven optimization in Cloudflare Workers that directly reduces wall-clock time for requests. The CI fix ensures that the project's automated verification remains functional.


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


Summary by cubic

Parallelized Cloudflare KV reads and writes with Promise.all to cut request latency. Fixed CI by moving Node to 22 and syncing the lockfile.

  • Refactors

    • KV operations in handleCreate, handleEdit, handleAbuseReport, and handleSubdomain now run in parallel.
    • No behavior changes; only latency reduction for independent I/O.
  • Dependencies

    • Updated GitHub Actions to Node 22 to match current wrangler requirements.
    • Synced package-lock.json for reliable npm ci.

Written for commit 915a377. Summary will update on new commits.

Review in cubic

- Refactor src/index.ts to use Promise.all for independent KV puts and gets.
- Update .github/workflows/test.yml to use Node.js 22 to satisfy dependency requirements.
- Ensure package-lock.json is synchronized.

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.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/index.ts">

<violation number="1" location="src/index.ts:96">
P2: Parallel content+meta writes can commit metadata on failed edits. Preserve write order so metadata changes only after content persistence succeeds.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/index.ts
const meta = JSON.stringify({ v: 1, h: tokenHash, t: ttlKey, ct: createdAtMs });
await env.NOTES.put(key, content, putOpts);
await env.NOTES.put("m:" + name, meta, putOpts);
await Promise.all([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Parallel content+meta writes can commit metadata on failed edits. Preserve write order so metadata changes only after content persistence succeeds.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/index.ts, line 96:

<comment>Parallel content+meta writes can commit metadata on failed edits. Preserve write order so metadata changes only after content persistence succeeds.</comment>

<file context>
@@ -93,8 +93,10 @@ async function handleCreate(req, env, url) {
   const meta = JSON.stringify({ v: 1, h: tokenHash, t: ttlKey, ct: createdAtMs });
-  await env.NOTES.put(key, content, putOpts);
-  await env.NOTES.put("m:" + name, meta, putOpts);
+  await Promise.all([
+    env.NOTES.put(key, content, putOpts),
+    env.NOTES.put("m:" + name, meta, putOpts),
</file context>

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