-
-
Notifications
You must be signed in to change notification settings - Fork 45
Description
Problem
In large vaults (thousands of images), the automatic cache cleanup causes noticeable UI freezing/stuttering. Cleanup takes 5+ seconds and blocks the main thread, making Obsidian unresponsive during the operation.
Steps to Reproduce
- Use a vault with 1000+ images across multiple notes
- Enable the image alignment feature (creates cache entries)
- Set Image alignment cache cleanup interval to any value > 0 (e.g., 60000ms)
- Wait for automatic cleanup to trigger
- Try interacting with the Obsidian UI during cleanup
Expected
Cleanup should be fast enough to avoid input delays, or at least not block the main thread.
Actual
Console logs:
Cache cleanup time: 8075ms
[Violation] Handling of 'wheel' input event was delayed for 5143 ms due to main thread being busy.
During cleanup, the UI is fully unresponsive for 5–8 seconds (typing/scrolling/clicking all blocked).
Root Cause
cleanCache() in src/ImageAlignmentManager.ts:636-691 uses an O(n²) nested-loop approach, repeatedly scanning vault files:
for (const notePath in this.cache) {
for (const imageHash in this.cache[notePath]) {
const allFiles = this.app.vault.getFiles(); // called repeatedly
for (const file of allFiles) { // iterates all vault files
const currentImageHash = this.getImageHash(notePath, file.path);
// ... hash comparison
}
}
}Performance Notes
Example vault:
- 100 notes with cached alignments
- 10 cached images per note
- 1000 image files
Total work ≈ 100 × 10 × 1000 = 1,000,000 hash calculations, run synchronously on the main thread, which causes the freezes.
Feature Request: Manual Cache Cleanup Button
Please add a manual cache cleanup button in the plugin settings tab. This allows users to:
- Disable automatic cleanup (set interval to 0 / Never)
- Manually trigger cleanup when needed (e.g., after deleting many images)
- Avoid periodic UI freezes in large vaults
Suggested Implementation
Add a button in src/ImageConverterSettings.ts:
Enhancement: "Never" Option for Cleanup Interval
Add a "Never (manual only)" option:
Current Workaround
Users can set imageAlignmentCacheCleanupInterval to 0, but there is no manual cleanup. To clean the cache now, users must:
- Change the interval to a non-zero value
- Wait for cleanup to trigger
- Change it back to 0 (and reload the plugin)
This is cumbersome and discourages cache cleanup entirely.
Environment
- Obsidian version: Latest
- Plugin version: 1.4.1
- OS: macOS / Windows / Linux
- Vault size: 3000+ images
- Impact: Severe — Obsidian becomes unusable for 5–8 seconds during cleanup
Related Code
src/ImageAlignmentManager.ts:636-691—cleanCache()src/ImageAlignmentManager.ts:815-828—scheduleCacheCleanup()src/ImageAlignmentManager.ts:72— initialization