Skip to content

perf(macos): start-up 31% faster (no CoreFoundation, chained fixups) - #435

Merged
mrnasil merged 6 commits into
mainfrom
perf/macos-no-corefoundation
Nov 7, 2026
Merged

mrnasil merged 6 commits into
mainfrom
perf/macos-no-corefoundation

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Update: two more macOS start-up fixes in this PR

  • Release. The arm64 release now targets macOS 13 (MACOSX_DEPLOYMENT_TARGET in release.yml; Intel stays 10.15). From 13.0 the linker emits chained fixups, which the kernel applies lazily as pages fault in, instead of dyld rebasing the binary's ~29k pointers before main (−0.23 ms). macOS 11 and 12 no longer get security updates. docs/packaging.md is updated.
  • Linker flag. -Wl,-dead_strip_dylibs on Apple targets (cli/build.rs) drops libiconv, which the libc crate links and nothing calls. otool -L now lists libSystem only.

Final numbers on the Apple M2, interleaved, 150 runs, median. The empty main is also built for 13.0.

v0.6.35 this PR
empty Rust exe (floor) 2.15 ms —
--version 3.81 ms 2.64 ms (−31%)
--help 4.04 ms 2.95 ms (−27%)
config show 4.96 ms 3.87 ms (−22%)

The remaining 0.49 ms over the floor is the 17 MB binary itself; there is no library or fix-up left to drop. The README macOS --version is now 2.6 ms.

Problem (first commit)

On macOS every whycodes process spent about 0.9 ms loading CoreFoundation before main ran.

Apple M2, median
Empty Rust main 2.08 ms
v0.6.35 --version 3.74 ms

otool -L lists only three libraries: libSystem, libiconv and CoreFoundation. I built them into an empty main one at a time: CoreFoundation alone adds 0.9 ms, libiconv 0.03 ms. dyld loads a linked framework at launch whether or not the program ever calls it.

CoreFoundation comes from chrono's clock feature: Local resolves the zone through iana-time-zone, which links the framework.

Change

  • New whycodes_core::local_time (offset_at, to_local, now):
    • Unix (macOS, Linux): uses localtime_r (tm_gmtoff), which lives in libSystem/libc and is already loaded.
    • Windows: keeps chrono's Local, which costs nothing extra there.
  • Callers. The two local-time reads use it: the Environment date (agent) and the TUI clocks (timefmt.rs).
  • Dependencies. The workspace chrono dependency drops default features, keeping std, now and serde. core re-enables clock for Windows only. Nothing else in the tree enables clock.
  • Result. macOS and Linux no longer link iana-time-zone. On a release build on the M2, otool -L lists only libSystem and libiconv.

Measured (Apple M2, release, interleaved, 100 runs, median)

v0.6.35 this PR
--version 3.74 ms 2.83 ms (−24%)
--help 4.00 ms 3.13 ms (−22%)

The remaining 0.75 ms over the empty-exe floor is the 17 MB binary itself (page-ins, fix-ups); there are no further libraries to drop. The README macOS --version becomes 2.8 ms, and docs/benchmarks.md gets the breakdown.

Checks

  • macOS (M2):
    • core 182, agent 768 and tui timefmt tests pass.
    • The new unix_offset_follows_tz sets TZ=UTC and then Asia/Tokyo and checks the offsets.
    • tui has one failure, clipboard_image::…prune_old_clipboard_images…, which fails identically on main on the Mac. It is pre-existing and macOS-only; CI does not run macOS.
  • Windows: core 181, agent 768, session 175 and tui 1496 pass. Workspace clippy and the ratchets are ok.
  • cargo tree per target: iana-time-zone / core-foundation are absent on macOS (except notify's objc2-core-foundation, which the linker drops) and on Linux.

🤖 Generated with Claude Code

mrnasil and others added 6 commits November 7, 2026 22:03
On macOS every whycodes process spent ~0.9 ms loading CoreFoundation
before main: chrono's `clock` feature resolves `Local` through
`iana-time-zone`, which links the framework, and dyld loads linked
frameworks at launch. An empty Rust main starts in 2.08 ms on an M2;
`--version` took 3.74 ms.

Local time is read in two places (the Environment date, the TUI clocks).
They now use `whycodes_core::local_time`: `localtime_r` on Unix, which
lives in libSystem/libc and is already loaded, and chrono's `Local` on
Windows only. The workspace chrono dependency drops default features
(`clock`), keeping `std`, `now` and `serde`; core turns `clock` back on
for Windows. macOS and Linux no longer link iana-time-zone; `otool -L`
lists only libSystem and libiconv.

Apple M2, interleaved, 100 runs, median: --version 3.74 -> 2.83 ms
(-24%), --help 4.00 -> 3.13 ms (-22%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil mrnasil changed the title perf(core): drop CoreFoundation from macOS start-up perf(macos): start-up 31% faster (no CoreFoundation, chained fixups) Nov 7, 2026
@mrnasil
mrnasil merged commit 5b9e524 into main Nov 7, 2026
7 checks passed
@mrnasil
mrnasil deleted the perf/macos-no-corefoundation branch November 7, 2026 19:45
@mrnasil mrnasil mentioned this pull request Nov 7, 2026
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.

1 participant