Skip to content

perf(finder): speed up right-click menus and reduce heartbeat overhead - #167

Merged
wflixu merged 1 commit into
wflixu:devfrom
SonneFish:codex/pr166-performance
Nov 2, 2026
Merged

wflixu merged 1 commit into
wflixu:devfrom
SonneFish:codex/pr166-performance

Conversation

@SonneFish

@SonneFish SonneFish commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Remove the recurring cold-icon rebuild from Finder’s right-click path and stop retransmitting an unchanged signed menu configuration every 10 seconds.

The original issue was not just a slow first launch: the heartbeat repeatedly invalidated the icon cache, making later right-clicks pay the cold-start cost again. This PR breaks that cycle, preloads expensive workspace lookups, and keeps liveness checks lightweight.

This is the standalone performance portion of #166, targeting dev.

Why right-clicks kept getting slow

Previously, each extension heartbeat caused the host to send the full menu configuration. Receiving that configuration cleared the extension’s entire icon cache. The next menu build then queried application icons synchronously through NSWorkspace.icon(forFile:) on the menu-building thread.

10-second heartbeat
  → encode/sign/send the full menu configuration
  → clear the extension's icon cache
  → next right-click performs cold workspace icon lookups again

A heartbeat could arrive between consecutive right-clicks, so this work was repeatedly paid during normal use rather than only at startup.

Performance changes

Source of repeated work Change Intended effect
Full configuration sent on every heartbeat Reply with a lightweight running payload; send configuration on changes, explicit requests, or reconnection Avoid repeatedly encoding, signing, transferring, decoding, and verifying the full unchanged configuration
Entire app icon cache cleared on configuration receipt Preserve existing cached icons Keep subsequent menu builds on the warm-cache path
App and file-type workspace lookups first performed during menu construction Preload those lookups on a utility queue when configuration arrives Move expensive lookup work ahead of the user's click when preloading completes
A 15-second monitor reset a live extension's state Track the last peer activity and detect actual timeout/reconnection with PeerActivity Prevent healthy heartbeats from repeatedly triggering full configuration resends

Workspace lookups run in the background. Image resizing, drawing, and cache merging remain on the main thread; background preloading does not call lockFocus. Menu-build timing remains logged so the standalone change can be measured in a signed Finder extension.

Earlier profiling

Profiling recorded during the original combined change in #166 showed:

Menu-build condition Recorded duration
Recurring cold rebuild after cache invalidation Approximately 55 ms
Warm-cache steady state Approximately 0.5–0.7 ms

These historical measurements explain the priority of preserving the cache. They are not a new benchmark or a verified approximately 100× speedup for this standalone PR. Cold-start and steady-state measurements for the current head remain on the validation checklist below.

Acceptance criteria

  • Configuration receipt preserves cached app icons.
  • App and file-type workspace lookups can be preloaded before menu construction, with main-thread image resizing and cache merging.
  • A continuous heartbeat stream keeps the peer online without periodic full configuration resends.
  • Timeout, reconnection, and explicit disconnection are covered by PeerActivity regression tests.

Validation

  • Xcode 27 build-for-testing: the app, Finder extension, and test targets build independently (arm64, code signing disabled).
  • All 63 tests pass in the temporary SwiftPM library test host. New PeerActivity tests cover continuous heartbeats, timeout/reconnection, and explicit disconnection.
  • The combined branches build successfully; all 68 tests in 12 suites pass in the temporary library test host.
  • git diff --check passes. Fork-specific signing, bundle identifiers, App Groups, and packaging scripts are excluded.
  • GitHub Actions builds and tests complete for this branch: run 41402801193 is action_required, awaiting maintainer approval via Approve and run; tests have not executed.
  • Measure cold-start and steady-state menu latency in the signed app, including repeated configuration changes, background icon queries, and heartbeat reconnection.

Risks and limitations

The earlier profiling figures above come from the original combined change. This standalone PR has not been rebenchmarked, so they are not a verified speedup for its current head. Recovery after a missed configuration update and behavior with multiple FinderSync instances still need validation in the signed app.

The regular local Xcode test host exited before executing tests. The temporary SwiftPM library host compiles the same production sources, excluding the app entry point; its results do not replace end-to-end testing of the signed app.

Related PRs

Split from #166 at the maintainer's suggestion:

Each PR targets dev and builds independently. Combining them in the order above was verified to merge without conflicts.

@SonneFish
SonneFish marked this pull request as ready for review November 2, 2026 06:58
@SonneFish SonneFish changed the title perf(finder): keep icon caches warm and lighten heartbeats perf(finder): eliminate recurring cold icon rebuilds on right-click Nov 2, 2026
@SonneFish SonneFish changed the title perf(finder): eliminate recurring cold icon rebuilds on right-click perf(finder): speed up right-click menus and reduce heartbeat overhead Nov 2, 2026
@wflixu
wflixu merged commit 1d15167 into wflixu:dev Nov 2, 2026
1 check passed
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