perf(desktop): debounce electron store persistence#37587
Open
Hona wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a buffered/debounced wrapper around electron-store in the Desktop main process to reduce synchronous disk I/O frequency by batching mutations in memory and flushing them later, with an explicit flush on shutdown.
Changes:
- Added
BufferedStoreto bufferset/delete/clearoperations and provide read-your-writes semantics before persistence. - Updated store lifecycle utilities to flush pending writes before deleting/cleaning store files.
- Added a shutdown hook in the Electron main process to flush all buffered stores before quitting, plus unit tests for core buffering behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| packages/desktop/src/main/store.ts | Adds BufferedStore, switches the store cache to buffered instances, and introduces flushAllStores() plus pre-delete flushes. |
| packages/desktop/src/main/store.test.ts | Adds tests for buffered read-before-flush, explicit flush persistence, and buffered deletes. |
| packages/desktop/src/main/index.ts | Flushes buffered stores on before-quit and will-quit shutdown events. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+92
to
+95
| private scheduleFlush() { | ||
| if (this.timer) return | ||
| this.timer = setTimeout(() => this.flush(), this.delay) | ||
| } |
| @@ -0,0 +1,58 @@ | |||
| import { describe, expect, test, beforeEach, afterEach, vi } from "bun:test" | |||
Comment on lines
+19
to
+21
| const underlying = new MemoryStore() | ||
| const store = new BufferedStore(underlying as any, 100) | ||
|
|
Comment on lines
+32
to
+34
| const underlying = new MemoryStore() | ||
| const store = new BufferedStore(underlying as any, 100) | ||
|
|
Comment on lines
+44
to
+48
| const underlying = new MemoryStore() | ||
| underlying.set("key1", "value1") | ||
|
|
||
| const store = new BufferedStore(underlying as any, 100) | ||
| store.delete("key1") |
Comment on lines
223
to
227
| app.on("before-quit", () => { | ||
| setAppQuitting() | ||
| flushAllStores() | ||
| void stopSidecars() | ||
| }) |
Comment on lines
+4
to
+15
| class MemoryStore { | ||
| public data = new Map<string, unknown>() | ||
| get(key: string) { | ||
| return this.data.get(key) | ||
| } | ||
| set(key: string, value: unknown) { | ||
| this.data.set(key, value) | ||
| } | ||
| delete(key: string) { | ||
| this.data.delete(key) | ||
| } | ||
| } |
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.
Summary
Applies an in-memory debounced write buffer (\BufferedStore) for \�lectron-store\ instances in the desktop main process.
Details