perf: speed up Cmd+N note creation from ~150ms to ~16ms (#81)

* fix: speed up Cmd+N note creation from ~150ms to ~16ms

Root cause: the editor focus used a fixed 150ms setTimeout after note
creation, even when the BlockNote editor was already mounted. The
optimistic UI (state updates, tab opening) was already synchronous,
but the focus delay dominated perceived latency.

Changes:
- Editor focus now uses requestAnimationFrame when editor is mounted
  (~16ms on 60Hz), falling back to 80ms timeout for first-mount only
- Rust save_note_content creates parent directories automatically,
  preventing optimistic-UI revert when creating notes in new folders
- Added perf timing markers (console.debug) to measure creation→focus

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* ci: retrigger after disk space cleanup

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Luca Rossi
2026-02-26 00:03:38 +01:00
committed by GitHub
parent 9e9096857d
commit ac4db43fd5
3 changed files with 54 additions and 5 deletions

View File

@@ -429,10 +429,21 @@ export const Editor = memo(function Editor({
tabPathsRef.current = currentPaths
}, [tabs])
// Focus editor when a new note is created (signaled via custom event)
// Focus editor when a new note is created (signaled via custom event).
// Uses adaptive timing: fast rAF path when editor is already mounted,
// short timeout when waiting for first mount.
useEffect(() => {
const handler = () => {
setTimeout(() => editor.focus(), 150)
const handler = (e: Event) => {
const t0 = (e as CustomEvent).detail?.t0 as number | undefined
const doFocus = () => {
editor.focus()
if (t0) console.debug(`[perf] createNote → focus: ${(performance.now() - t0).toFixed(1)}ms`)
}
if (editorMountedRef.current) {
requestAnimationFrame(doFocus)
} else {
setTimeout(doFocus, 80)
}
}
window.addEventListener('laputa:focus-editor', handler)
return () => window.removeEventListener('laputa:focus-editor', handler)