Skip to content

perf: batch DOM work, defer remote images, selective vault refresh#19

Open
davidvkimball wants to merge 3 commits into
0qln:masterfrom
davidvkimball:master
Open

perf: batch DOM work, defer remote images, selective vault refresh#19
davidvkimball wants to merge 3 commits into
0qln:masterfrom
davidvkimball:master

Conversation

@davidvkimball
Copy link
Copy Markdown
Contributor

  • Debounce mutation batches and schedule work via requestIdleCallback
  • Skip heavy work when alt has no @; memoize filter parsing; dedupe in-flight work
  • Defer remote image processing until near viewport (IntersectionObserver)
  • On vault modify, only reprocess images tied to changed file paths
  • Bump version to 1.2.5

This vastly reduces startup time.

Add "Theme Aware Mode" setting that makes @DarkMode filter automatically
adapt to Obsidian's current theme (light/dark). When enabled, images
intelligently adjust filtering based on active theme.

Features:
- OFF by default for backward compatibility
- Dark theme: inverts colors, removes dark backgrounds, boosts lightness
- Light theme: keeps original colors, removes bright backgrounds, reduces lightness
- Auto-reprocessing when theme changes
- Theme-aware cache system (separate files per theme)

Implementation:
- Add theme detection via body.className (theme-light/theme-dark)
- Add MutationObserver to watch for theme changes
- Update DarkModeFilter with conditional logic based on theme parameter
- Update ImageFilter interface with optional theme parameter
- Update ImageCache to include theme in cache keys
- Add setting toggle in plugin settings tab

Modified files:
- main.ts - theme detection, observer, setting
- filters/ImageFilter.ts - add optional theme parameter
- filters/DarkModeFilter.ts - theme-aware filtering logic
- ImageCache.ts - theme-aware cache keys
- README.md - documentation
- Debounce mutation batches and schedule work via requestIdleCallback
- Skip heavy work when alt has no @; memoize filter parsing; dedupe in-flight work
- Defer remote image processing until near viewport (IntersectionObserver)
- On vault modify, only reprocess images tied to changed file paths
- Bump version to 1.2.5
@0qln
Copy link
Copy Markdown
Owner

0qln commented Apr 23, 2026

This vastly reduces startup time.

I have not noticed any performance issues with my plugin. Care to add a benchmark? Especially with the filter parsing cache... I doubt that exceeds even a millisecond per filter.

@davidvkimball
Copy link
Copy Markdown
Contributor Author

Honestly this could be a false positive. For some reason I measured startup and it was wildly slow, but I can't get it to reproduce it so it must have been some one off incident. After I had made some tweaks it more performant, but don't have the stats with me. You can close this PR if you want.

@0qln
Copy link
Copy Markdown
Owner

0qln commented Apr 23, 2026

all good, thanks for trying to improve it ^^

i'll leave this PR open for now, maybe I'll find the time to review the code in the future :)

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