Fix popup hotkey re-registration leak#1456
Conversation
|
While working on the preview path in my fork, I ran into three separate and important preview/UI performance issues. They remain out of scope for this PR, but I want to record them as possible follow-ups. I rechecked the commit history through the final fork snapshot immediately before the Swift 6 / strict-concurrency migration. The actual final chains were:
The fork has diverged substantially since these changes landed. These commits document behavior that survived to the final pre-migration snapshot; they are references and evidence, not patches that can be cherry-picked. Each issue would need to be revisited independently and adapted into a small upstream-compatible change. |
e550b6a to
be842f4
Compare
Avoid disabling and re-enabling the popup shortcut for every open/close cycle. KeyboardShortcuts registers a new Carbon hotkey when re-enabled, causing the backing allocations to accumulate. Route repeated popup shortcut presses through the existing popup state machine while keeping the process-wide registration alive.
be842f4 to
29d4454
Compare
|
One more candid note after checking the current upstream path: OCR is eager, not search-triggered. Every accepted clipboard entry is passed through Honestly, I do not think OCR earns its cost as an always-on built-in clipboard feature. My expectation—not a measured statistic—is that in well over 90% of image clipboard usage, users will never need to find those images by recognized text. Spending compute and energy on every image copy for a rarely used capability looks like a poor resource trade-off to me. For that reason I removed the Vision OCR image-title feature from my fork. If OCR remains upstream, I think it should at least be opt-in and/or lazy rather than running for every copied image. |
|
Do you have any data indicating that hotkey registration causes actual significant memory usage?
In my experience there is no significant lag during search/delete/pin etc. Can you give an example, where this is the case for you. The animation exists very deliberately.
What is the rational behind this proposed change? SwiftUI already handles downsampling images under the hood.
Again, do you have actual evidence that this is a problem? Usually SwiftUI already handles coalescing layout invalidation quite well.
OCR happens on a background thread. Having OCR run before deduplication is also not a very urgent issue as images in the clipboard are near impossible to be deduplicated anyways. As above, do you have data supporting image OCR taking up significant resources? With the next update the OCR text from images can directly be copied from the UI, which - in my opinion - makes this a valuable feature. |
|
Then there's the issue of downsampling. I'm not familiar with Swift features; I just followed my previous development approach and did it directly. So it might be incorrect. But I implemented multilayer cache. So I store downsampled image in memory, and leave origin image in disk to save memory. Next, regarding OCR, I prefer that if a feature isn't used but runs frequently, then it's unnecessary. So I removed it. Of course, this is just a personal habit of mine and my friend's; I'm not sure how many people actually use OCR. But I still maintain my opinion that this feature is unnecessary. |
|
Problem 3 and Problem 1 are directly related; improving Problem 1 will greatly alleviate Problem 3. However, the behavior will differ from my current fork. In my fork, I made the following modifications based on my personal habits:
|
|
And the memory leak issue ,as you've seen, the app performs terribly with large text, and I frequently need to use ChatGPT for my studies. Furthermore, verifying a clear memory leak requires a long run, so I'm temporarily unwilling to provide this evidence myself, as it significantly impacts usability. |
|
Maccy-dry-run-818f03d-2.6.1-60.zip my fork app. If you worry about any safety, security issue with this app. (I know there was a fake maccy) You can fork my fork, check it with AI, and run github workflow to build yourself. |



Summary
flagsChangedmonitor needed for release-to-select behaviorRoot cause
Opening the popup disabled
.popup, and closing it enabled the shortcut again. In KeyboardShortcuts 2.0.2, that pair unregisters the Carbon hotkey and registers a new one. The Carbon backing allocations accumulated across popup open/close cycles.Keeping the global registration alive removes that allocation cycle. Toggle, ordinary repeated presses, and release-to-select continue to use the existing popup state machine.
Known test difference
testOpenAndSelectThirdItemRepeatedPressposts multiple synthetic key-down events without intervening key-up events. With the Carbon hotkey left registered, those extra raw events do not reach the local AppKit monitor, so that test remains red. The minimal leak fix is intentionally kept here; compatibility with that synthetic repeat sequence can be handled separately if it reflects required runtime behavior.Validation
04298ab2), which observed 783 live Carbon hotkey allocations using 43.5 MB after extended usedisableunregisters,enablecallsRegisterEventHotKey, and handled hotkey events returnnoErrmastergit diff --checkpasses