Skip to content

perf(main): debounce synchronous file writes to reduce main thread blocking#11

Draft
monotykamary wants to merge 1 commit intoSuperCmdLabs:mainfrom
monotykamary:perf/debounce-sync-writes
Draft

perf(main): debounce synchronous file writes to reduce main thread blocking#11
monotykamary wants to merge 1 commit intoSuperCmdLabs:mainfrom
monotykamary:perf/debounce-sync-writes

Conversation

@monotykamary
Copy link
Contributor

@monotykamary monotykamary commented Feb 18, 2026

Summary

Some quick wins to avoid that "freezing" feeling when opening the clipboard history on top of the other things. Adds write debouncing to reduce blocking I/O operations on the main thread during frequent clipboard and snippet operations.

Changes

Debounced Writes (100ms)

  • clipboard-manager.ts: saveHistory() - batches clipboard history writes
  • snippet-store.ts: saveToDisk() - batches snippet modification writes
  • memory.ts: writeLocalMemories() - batches memory writes
  • settings-store.ts:
    • Added saveSettingsAsync() for non-blocking settings writes
    • Debounced saveOAuthTokens() for OAuth token persistence

Directory Creation Optimization

  • Moved fs.existsSync + mkdirSync calls from hot paths to startup:
    • clipboard-manager: ensureClipboardDirs() called once on monitor start
    • snippet-store: ensureSnippetsDir() called once on init

Impact

  • Reduces main thread blocking during rapid copy operations
  • Batches multiple quick edits into single disk writes
  • Improves responsiveness during heavy clipboard/snippet usage

Testing

  • TypeScript compilation passes
  • All existing functionality preserved
  • Debouncing only affects write timing, not behavior

…ocking

Add write debouncing (100ms) to frequently modified stores:
- clipboard-manager: debounce saveHistory() calls
- snippet-store: debounce saveToDisk() calls
- memory: debounce writeLocalMemories() calls
- settings-store: debounce OAuth token saves + add saveSettingsAsync()

Move directory creation to startup to avoid repeated fs.existsSync checks:
- clipboard-manager: ensureClipboardDirs() on monitor start
- snippet-store: ensureSnippetsDir() on init

Reduces blocking I/O during rapid clipboard operations and frequent
snippet modifications.
Copy link
Contributor Author

@monotykamary monotykamary left a comment

Choose a reason for hiding this comment

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

Although logically sound (and not much to break here), there does need to be a performance harness for us to validate it instead of vibe testing it.

@shobhit99
Copy link
Contributor

Although logically sound (and not much to break here), there does need to be a performance harness for us to validate it instead of vibe testing it.

I will look into performance testing tools today. will test these changes manually for now. Thanks!

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.

2 participants