perf: faster startup and long pages

- open the window while the notes folder loads; rebuild the search index after the page list is sent
- load mermaid and katex on demand
- vault.list reads files in parallel batches
- resolveLink uses a per-page-list lookup table
- very long pages (>300 blocks) skip layout of off-screen blocks
- perf-large: add a long-page case, fix the tasks poll

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Your NameandClaude Sonnet 5.5 committed 2026-10-15 12:25:45 +02:00
1 parent fcad23afa9
commit d5d25eaf46
10 files changed
+147 -64

No files matched your search

+9 -3
View File
@@ -67,7 +67,11 @@ async function openVault(dir) {
vault = new Vault(dir, { trash: (p) => shell.trashItem(p) });
db = openDb(path.join(dir, '.notes', 'index.sqlite'));
const pages = await vault.list();
db.rebuild(pages);
// The index is only a cache of the files, so refresh it once the window has its page list.
const opened = vault;
setTimeout(async () => {
try { if (vault === opened) db.rebuild(await vault.list()); } catch (err) { console.error('Could not rebuild the search index', err); }
}, 300).unref();
const trashDays = prefs().trashDays;
if (trashDays > 0) vault.purgeOlderThan(trashDays).catch((err) => console.error('Could not clear old trash', err));
stopWatch = vault.watch(async (ids) => {
@@ -162,7 +166,9 @@ function need() {
const handle = (channel, fn) => ipcMain.handle(channel, (_event, ...args) => fn(...args));
handle('vault:get', () => snapshot());
// The window is created while the folder is still opening; the page's first question waits for it.
let opening = null;
handle('vault:get', async () => { if (opening) await opening.catch(() => {}); return snapshot(); });
handle('vault:list', () => snapshot());
handle('vault:pick', async (kind) => {
let dir;
@@ -757,7 +763,7 @@ app.whenReady().then(async () => {
const s = settings.get();
if (s.vault && fs.existsSync(s.vault)) {
try { await openVault(s.vault); } catch (err) { console.error('Could not open notes folder', err); }
opening = openVault(s.vault).catch((err) => { console.error('Could not open notes folder', err); });
}
createWindow();
applyPrefs();