Give thumbnails their own cheap, low-resolution load path - #162
Merged
Conversation
Integrates supernote-typescript#41 (merged to that repo's main), closing supernote-typescript#40: toImage() now accepts a `scale` downsample factor and decodes directly at the reduced resolution (RattaRLEDecoder.decodeAtScale) rather than decoding at full resolution and shrinking afterward - a full pageWidth x pageHeight buffer is never allocated. On a real 1404x1872 page that's a ~10MB decode (full res) vs. ~100KB (scale 10) - confirmed in that PR. Threads an optional `scale` parameter through the whole rasterization path: ImageConverter.convertToImages -> WorkerPool.processPages/ processChunk -> the SupernoteWorkerMessage sent to the Worker -> supernote-typescript's toImage() itself. Previously, SupernoteView's thumbnail sidebar reused ensurePageImage() - the exact same full-page-resolution path the main view uses - just to fill in a ~140px preview, paying the same decode/memory cost as actually viewing the page (the root inefficiency behind issue #154's crash trail: #156's rootMargin fix and #159's debounce both worked around *how often* this fired, not *how expensive* each individual thumbnail load was). Gives thumbnails their own entirely separate state (thumbnailDataUrl/thumbnailLoadPromise) and load/evict cycle (ensureThumbnail()/evictThumbnail()) at THUMBNAIL_SCALE (4, chosen so a typical ~1400px-wide page decodes to ~350px - comfortably above the sidebar's own width with headroom for higher-DPI displays), fully decoupled from ensurePageImage()/evictPageImage()'s full-resolution main-view state - a thumbnail being visible no longer implies (or requires) the main view's own image to load, and vice versa, since neither shares a resolution or cost with the other anymore.
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Integrates supernote-typescript#41 (merged), closing supernote-typescript#40 - the follow-up filed while debugging #154.
toImage()now accepts ascaledownsample factor and decodes directly at the reduced resolution (RattaRLEDecoder.decodeAtScale) rather than decoding at full resolution and shrinking afterward - a fullpageWidth×pageHeightbuffer is never allocated. On a real 1404×1872 page that's a ~10MB decode (full res) vs. ~100KB (scale 10), per that PR's own measurements.This addresses the root inefficiency behind #154's whole crash trail: the thumbnail sidebar was reusing
ensurePageImage()- the exact same full-page-resolution path the main view uses - just to fill in a ~140px preview. #156'srootMarginfix and #159's debounce both worked around how often that fired, not how expensive each individual thumbnail load actually was.Changes
scaleparameter through the whole rasterization path:ImageConverter.convertToImages→WorkerPool.processPages/processChunk→ theSupernoteWorkerMessagesent to the Worker →toImage()itself.supernote-typescriptsubmodule to the merged commit.thumbnailDataUrl/thumbnailLoadPromise) and load/evict cycle (ensureThumbnail()/evictThumbnail()) at a newTHUMBNAIL_SCALE = 4(a ~1400px-wide page decodes to ~350px - comfortably above the sidebar's own ~140px width, with headroom for higher-DPI displays), fully decoupled fromensurePageImage()/evictPageImage()'s full-resolution main-view state. A thumbnail being visible no longer implies (or requires) the main view's own image to load, and vice versa - neither shares a resolution or cost with the other anymore.What I could not verify
Same caveat as the rest of this issue's PRs: no Obsidian/Electron/X server in my environment. Did directly verify the underlying scaled decode against a real fixture (
tests/input/a5x-2.14.28.note, 1404×1872):scale: 4correctly produces a 351×468 image. The rest (worker message plumbing, thumbnail sidebar wiring) is verified viatsc/eslint/tests and careful tracing, not by actually opening a real note.Test plan
npx tsc --noEmit- cleannpx eslint src/main.ts src/myworker.worker.ts- 0 errorsnpx vitest run- 95 passednpm run build- cleantoImage(sn, [1], { scale: 4 })against a real fixture produces correct output dimensions (351×468 from a 1404×1872 page)