Repository navigation
perf(macos): start-up 31% faster (no CoreFoundation, chained fixups) - #435
Merged
Merged
Conversation
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]>
… macOS Co-Authored-By: Claude Opus 5.5 <[email protected]>
…libs Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
Update: two more macOS start-up fixes in this PR
MACOSX_DEPLOYMENT_TARGETinrelease.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 beforemain(−0.23 ms). macOS 11 and 12 no longer get security updates.docs/packaging.mdis updated.-Wl,-dead_strip_dylibson Apple targets (cli/build.rs) drops libiconv, which thelibccrate links and nothing calls.otool -Lnow lists libSystem only.Final numbers on the Apple M2, interleaved, 150 runs, median. The empty
mainis also built for 13.0.--version--helpconfig showThe 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
--versionis now 2.6 ms.Problem (first commit)
On macOS every whycodes process spent about 0.9 ms loading CoreFoundation before
mainran.main--versionotool -Llists only three libraries: libSystem, libiconv and CoreFoundation. I built them into an emptymainone 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
clockfeature:Localresolves the zone throughiana-time-zone, which links the framework.Change
whycodes_core::local_time(offset_at,to_local,now):localtime_r(tm_gmtoff), which lives in libSystem/libc and is already loaded.Local, which costs nothing extra there.agent) and the TUI clocks (timefmt.rs).chronodependency drops default features, keepingstd,nowandserde.corere-enablesclockfor Windows only. Nothing else in the tree enablesclock.iana-time-zone. On a release build on the M2,otool -Llists only libSystem and libiconv.Measured (Apple M2, release, interleaved, 100 runs, median)
--version--helpThe 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
--versionbecomes 2.8 ms, anddocs/benchmarks.mdgets the breakdown.Checks
core182,agent768 andtuitimefmt tests pass.unix_offset_follows_tzsetsTZ=UTCand thenAsia/Tokyoand checks the offsets.tuihas one failure,clipboard_image::…prune_old_clipboard_images…, which fails identically onmainon the Mac. It is pre-existing and macOS-only; CI does not run macOS.core181,agent768,session175 andtui1496 pass. Workspace clippy and the ratchets are ok.cargo treeper target:iana-time-zone/core-foundationare absent on macOS (exceptnotify'sobjc2-core-foundation, which the linker drops) and on Linux.🤖 Generated with Claude Code