Skip to content

⚡ Bolt: Optimize sequential IndexedDB writes in loadNotesIntent - #5

Merged
davidraehles merged 3 commits into
mainfrom
bolt-optimize-indexeddb-writes-10663017803853492186
Feb 18, 2026
Merged

⚡ Bolt: Optimize sequential IndexedDB writes in loadNotesIntent#5
davidraehles merged 3 commits into
mainfrom
bolt-optimize-indexeddb-writes-10663017803853492186

Conversation

@davidraehles

Copy link
Copy Markdown
Collaborator

💡 What: The optimization replaces sequential IndexedDB writes (one transaction per item) with a single bulk transaction for multiple items in loadNotesIntent.

🎯 Why: Opening a transaction for each item is very slow due to the overhead of transaction creation and coordination in IndexedDB. Using a single transaction for all items is a standard and highly effective optimization.

📊 Measured Improvement:
Using a simulated benchmark with 50 items and 10ms transaction overhead:

  • Baseline (Sequential): ~580ms (50 transactions)
  • Optimized (Bulk): ~70ms (1 transaction)
  • Improvement: ~8.2x faster over baseline.

Verified by running the benchmark and existing tests. No regressions introduced.


PR created automatically by Jules for task 10663017803853492186 started by @davidraehles

- Added `saveNotesToDB` to `offline.ts` to support bulk writes in a single transaction.
- Modified `loadNotesIntent` in `notesIntents.ts` to use `saveNotesToDB` instead of sequential `saveNoteToDB` calls.
- Established a benchmark demonstrating ~8x performance improvement for bulk writes.
Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
CopilotAI review requested due to automatic review settings February 18, 2026 19:30
@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.

CopilotAI 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.

Pull request overview

This PR optimizes offline caching during loadNotesIntent by replacing per-note IndexedDB writes (one transaction per note) with a single bulk transaction, reducing transaction overhead and improving load performance.

Changes:

  • Added saveNotesToDB(notes: Note[]) to write multiple notes in one IndexedDB transaction.
  • Updated loadNotesIntent to persist decrypted notes via the new bulk write helper.
  • Added frontend/pnpm-lock.yaml and a short benchmark note in .jules/bolt.md.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.

FileDescription
frontend/src/services/offline.tsAdds saveNotesToDB bulk write helper using a single readwrite transaction.
frontend/src/intents/notesIntents.tsSwitches loadNotesIntent to bulk-save decrypted notes to IndexedDB.
frontend/pnpm-lock.yamlIntroduces a pnpm lockfile (currently alongside an existing package-lock.json).
.jules/bolt.mdDocuments the bulk-write optimization and benchmark numbers.
Files not reviewed (1)
  • frontend/pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadfrontend/src/services/offline.ts Outdated
Comment on lines +52 to +54
for (const note of notes) {
tx.store.put(note);
}

CopilotAIFeb 18, 2026

Copy link

Choose a reason for hiding this comment

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

tx.store.put(note) returns a Promise in idb; ignoring it can lead to unhandled rejections if a put fails (even though tx.done will reject). Consider awaiting each put inside the loop, or collecting the promises and awaiting them (e.g., await Promise.all(...)) before awaiting tx.done so failures are properly observed and no promise is left floating.

Suggested change
for(constnoteofnotes){
tx.store.put(note);
}
constputPromises: Promise<unknown>[]=[];
for(constnoteofnotes){
putPromises.push(tx.store.put(note));
}
awaitPromise.all(putPromises);

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Collected put promises into an array and awaiting them with Promise.all before tx.done.

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.

Excellent suggestion. I've updated saveNotesToDB to collect all put promises and await them alongside tx.done using Promise.all for better efficiency and explicit completion tracking.

Comment threadfrontend/pnpm-lock.yaml Outdated
Comment on lines +1 to +5
lockfileVersion: '9.0'

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

CopilotAIFeb 18, 2026

Copy link

Choose a reason for hiding this comment

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

This PR introduces pnpm-lock.yaml, but the repo already has frontend/package-lock.json and there’s no indication that pnpm is used/configured (no packageManager field, no pnpm docs/scripts). Keeping two lockfiles for the same package.json is likely to cause dependency drift and CI/tooling confusion; please remove pnpm-lock.yaml (or, if migrating to pnpm, remove package-lock.json and update docs/CI accordingly).

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Removed pnpm-lock.yaml from the repository.

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.

Removed pnpm-lock.yaml as requested to keep the repository clean of this artifact.

Comment threadfrontend/src/intents/notesIntents.ts Outdated
Comment on lines +86 to +87
// Save to IndexedDB in bulk
await saveNotesToDB(decryptedNotes);

CopilotAIFeb 18, 2026

Copy link

Choose a reason for hiding this comment

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

Switching to a single transaction changes failure semantics: if any put fails, IndexedDB will abort the whole transaction and none of the notes will be persisted. Previously, each note was saved in its own transaction, so you could end up with a partially populated offline cache. Please confirm the all-or-nothing behavior is intended; if not, consider chunking or falling back to per-item writes on transaction abort so some notes still get cached.

Suggested change
// Save to IndexedDB in bulk
awaitsaveNotesToDB(decryptedNotes);
// Save to IndexedDB in bulk when possible; fall back to per-note saves on failure
try{
awaitsaveNotesToDB(decryptedNotes);
}catch{
for(constnoteofdecryptedNotes){
try{
awaitsaveNoteToDB(note);
}catch{
// Ignore individual failures to allow partial offline caching
}
}
}

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Added try/catch around saveNotesToDB with a per-item saveNoteToDB fallback so partial offline caching still works if the bulk transaction fails.

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.

Great point. I've added a try/catch block around the bulk save operation. If it fails, it will now fall back to sequential saveNoteToDB calls, ensuring that partial offline caching still works and providing more resilience.

OpenCodeand others added 2 commits February 18, 2026 21:13
- Updated `saveNotesToDB` to use `Promise.all` for `put` operations.
- Added try/catch with fallback to sequential save in `loadNotesIntent`.
- Removed `pnpm-lock.yaml` from the repository.
Co-authored-by: davidraehles <6085055+davidraehles@users.noreply.github.com>
@davidraehles
davidraehles merged commit 01a6ef3 into mainFeb 18, 2026
davidraehles added a commit that referenced this pull request Feb 18, 2026
Sign up for freeto 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.

3 participants

@davidraehles@OpenCode