Skip to content

fix: reduce ram usage#1446

Open
sesky4 wants to merge 2 commits into
p0deje:masterfrom
sesky4:master
Open

fix: reduce ram usage#1446
sesky4 wants to merge 2 commits into
p0deje:masterfrom
sesky4:master

Conversation

@sesky4

@sesky4 sesky4 commented Jul 8, 2026

Copy link
Copy Markdown

Summary

Hi, I found Maccy uses ~2.4 GB of memory at startup on my machine with a large clipboard history (hundreds of items with images/RTF blobs). Others have reported the same issue (#1240 #1294 #1129 #1088). This PR reduces startup memory.

Issues

  1. Unbounded fetchHistory.load() uses a FetchDescriptor<HistoryItem>() with no fetchLimit, eagerly loading every row and all contents relationships into memory.
  2. Inline blob storageHistoryItemContent.value stores image/RTF blobs inline in SQLite, so every fetch hydrates all of them into __DataStorage._bytes.
  3. Full-table fetch on every copyfindSimilarItem() does another unbounded FetchDescriptor<HistoryItem>() per clipboard change for dedup.
  4. Eager thumbnail generationensureThumbnailImage() decodes full-resolution NSImage for every row during view construction, even when the popup isn't visible.

Changes

  • HistoryItemContent.value: add @Attribute(.externalStorage) so blobs are stored out-of-line and loaded lazily.
  • History.load(): separate pinned (unlimited) and unpinned (fetchLimit = min(size, 50)) fetches, each sorted by the user's sort order.
  • findSimilarItem(): search the in-memory all array instead of doing a full-table fetch.
  • HistoryItemView: gate ensureThumbnailImage() on scenePhase == .active.

Testing

macOS 26.5.1, 1,140 items in DB (SQLite file ~2.8 GB).

Metric Before After
Physical footprint 2.4 GB 59 MB
RSS ~2.4 GB 116 MB

Filling 999 slots with fresh text copies kept memory stable at ~59 MB. Pins, search, delete, paste stack all work.

Backward compatibility

@Attribute(.externalStorage) triggers a transparent Core Data migration on first launch. Existing data is preserved — no data loss.

@sesky4 sesky4 changed the title fix: reduce startup memory fix: reduce ram usage Jul 8, 2026
@weisJ

weisJ commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator
  1. Unbounded fetchHistory.load() uses a FetchDescriptor<HistoryItem>() with no fetchLimit, eagerly loading every row and all contents relationships into memory

Your fix just effectively sets the history limit to 50. How are you handling if someone wants to search for content older than the last 50 entries?

  1. Inline blob storageHistoryItemContent.value stores image/RTF blobs inline in SQLite, so every fetch hydrates all of them into __DataStorage._bytes.

Do you have data that Attribute(.externalStorage) on its own reduces the memory footprint? Where do you have the information from that it will not load the data into memory?

  1. Full-table fetch on every copyfindSimilarItem() does another unbounded FetchDescriptor<HistoryItem>() per clipboard change for dedup.

Already handled in #1441. Note that while this improves performance when copying I found to real effect of it on memory usage.

  1. Eager thumbnail generationensureThumbnailImage() decodes full-resolution NSImage for every row during view construction, even when the popup isn't visible.

Thumbnails are generated as soon as an item is displayed. Not on view creation.

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