Initial indexing crawls while the window is hidden: links are resolved only about once a minute, so the metadata cache stays not clean

Steps to reproduce

  1. Make a vault of linked notes that Obsidian has never opened, so nothing is cached. The script under Additional information writes 30,000 short notes with 5 wikilinks each.

  2. Open the folder as a new vault (“Open folder as vault”).

  3. Straight away, before indexing finishes, open the developer console and hide the window for two minutes:

    const w = require('electron').remote.getCurrentWindow(); w.hide(); setTimeout(() => w.show(), 120000);
    
  4. When the window comes back, run:

    ({
      resolved: Object.keys(app.metadataCache.resolvedLinks).length,
      queued: app.metadataCache.linkResolverQueue?.items?.length,
      clean: app.metadataCache.isCacheClean()
    })
    

Did you follow the troubleshooting guide?

Yes. No community plugins, default theme and settings.

Expected result

Indexing takes about as long whether or not the window is visible. With the window visible, this vault is fully indexed in about 33 seconds, so after two minutes queued is 0 and clean is true.

Actual result

The notes are all parsed within about 90 seconds either way, but while the window is hidden, link resolution runs only in short bursts about once a minute. After two minutes hidden, thousands of notes are still queued and clean is false. Anything waiting on metadataCache.onCleanCache() waits too, including plugins that wait for the index before they start.

Measured on the generated vault (30,000 notes), a fresh profile each time, so nothing was cached:

Window Fully indexed after
visible 33 s
hidden 380 s

In the hidden run, resolution moved only at 63 s, 123 s, 183 s, 244 s, 305 s and 380 s. Between those points, nothing moved at all.

The same thing on a copy of a real vault (35,598 notes, more links per note) never finished while hidden:

Window Plugins Result
visible none fully indexed after 383 s
visible 5 community plugins fully indexed after 428 s
hidden none not finished after 855 s: 20,820 resolved, 14,778 still queued
hidden 5 community plugins not finished after 1,508 s: resolved count stuck at 15,640 from 127 s to 1,108 s, then 19,100 resolved with 16,498 still queued

In every hidden run, parsing finished (inProgressTaskCount reached 0) and only the link resolver queue was left. A CPU profile of the renderer during such a stall was 94% idle, so it is waiting, not working.

Environment

SYSTEM INFO:
	Obsidian version: 1.15.0
	Installer version: 1.14.5
	Operating system: Windows 11 Pro 10.0.26300
	Login status: not logged in
	Language: en
	Insider build toggle: off
	Live preview: on
	Base theme: adapt to system
	Community theme: none
	Snippets enabled: 0
	Restricted mode: on

RECOMMENDATIONS:
	none

Additional information

Where it comes from, as far as I can read the 1.15.0 bundle. MetadataCache.linkResolver() works through the queue in a loop that pauses every 10 notes, once more than 5 ms have passed. Each pause waits for requestIdleCallback(..., { timeout: 100 }) or a 100 ms setTimeout, whichever fires first. Chromium throttles both while the window is hidden, and the main window is created without backgroundThrottling: false. So a loop that yields every 10 notes gets very few wake-ups, which matches the once-a-minute bursts above. I hid the window with BrowserWindow.hide() for these measurements. I expect a minimized window, or one fully covered by other windows, to be throttled the same way, but I did not measure that.

Possible fixes: yield through something hidden windows do not throttle (a MessageChannel message, or scheduler.yield()), or resolve by time slice rather than every 10 notes, so that each throttled wake-up still resolves a full batch.

Related, but a different code path: Reading view tab stays blank until closed and reopened: its redraw waits on another (hidden) window's frames (a Reading view redraw waiting on a hidden window’s animation frames).

Script that writes the test vault (Node.js, node make-vault.mjs <folder>):

import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';

const vault = process.argv[2];
const count = 30000;
let seed = 4922;
const random = () => (seed = (seed * 1103515245 + 12345) % 2147483648) / 2147483648;
const name = (i) => `Note ${String(i).padStart(5, '0')}`;

for (let i = 0; i < count; i++) {
  const folder = join(vault, `Folder ${String(Math.floor(i / 1000)).padStart(2, '0')}`);
  mkdirSync(folder, { recursive: true });
  const links = Array.from({ length: 5 }, () => `[[${name(Math.floor(random() * count))}]]`);
  writeFileSync(join(folder, `${name(i)}.md`), `# ${name(i)}\n\nSome text that links to ${links.join(', ')}.\n\n- a list item #tag${i % 50}\n`);
}
2 Likes