From af77e2c944a4db6341cd81d12bfad6cee74115f6 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 23 Dec 2025 19:38:11 -0800 Subject: [PATCH] perf(deps): minimize objc2 cargo features to reduce build time This commit optimizes the objc2 dependency tree by disabling default features and enabling only the minimal set of features actually used by the codebase. This reduces compilation time and dependency bloat. I was meant to do this earlier but during the initial implementation it was easier to just pull in everything. Now that we are getting ready for a public release it's time to improve on this. I ended up: * Removing unused direct dependencies: - objc2-core-services - objc2-core-video * Setting `default-features = false` on all objc2 crates and added only the specific features required for the types and methods used * Updating objc2, objc2-app-kit, objc2-foundation, objc2-application-services, objc2-core-foundation, objc2-core-graphics, and objc2-quartz-core with minimal feature sets After all those changes, the following transitive dependencies are no longer pulled in: objc2-metal, objc2-core-image, objc2-core-data, objc2-cloud-kit, objc2-core-text, and loads of unused Foundation/AppKit class bindings. Some before and after numbers: | Metric | Before | After | Change | |---------------------------------|---------|---------|----------| | objc2 dep lines (komorebi) | 84 | 50 | -40.5% | | objc2 dep lines (komorebi-bar) | 91 | 59 | -35.2% | | Dependency tree (komorebi) | 973 | 917 | -5.8% | | Dependency tree (komorebi-bar) | 1181 | 1131 | -4.2% | | Clean build time | 3m 05s | 2m 21s | -23.8% | The almost 24% reduction in clean build time is a big win! --- Cargo.lock | 121 +++------------------------------------- justfile | 2 +- komorebi-bar/Cargo.toml | 7 ++- komorebi/Cargo.toml | 86 ++++++++++++++++++++++++---- 4 files changed, 88 insertions(+), 128 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36227a49..e4178c1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3019,8 +3019,6 @@ dependencies = [ "objc2-application-services", "objc2-core-foundation", "objc2-core-graphics", - "objc2-core-services", - "objc2-core-video", "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.2", "parking_lot", @@ -3897,8 +3895,8 @@ dependencies = [ "block2 0.5.1", "libc", "objc2 0.5.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-core-data", + "objc2-core-image", "objc2-foundation 0.2.2", "objc2-quartz-core 0.2.2", ] @@ -3910,16 +3908,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.10.0", - "block2 0.6.2", "libc", "objc2 0.6.3", - "objc2-cloud-kit 0.3.2", - "objc2-core-data 0.3.2", "objc2-core-foundation", "objc2-core-graphics", - "objc2-core-image 0.3.2", - "objc2-core-text", - "objc2-core-video", "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.2", ] @@ -3932,11 +3924,7 @@ checksum = "69282c2b5bc58fba07cb9de2113619532eb551e98efe3d8d695509ef45fbd53b" dependencies = [ "bitflags 2.10.0", "libc", - "objc2 0.6.3", "objc2-core-foundation", - "objc2-core-graphics", - "objc2-core-services", - "objc2-foundation 0.3.2", ] [[package]] @@ -3952,17 +3940,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-cloud-kit" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c" -dependencies = [ - "bitflags 2.10.0", - "objc2 0.6.3", - "objc2-foundation 0.3.2", -] - [[package]] name = "objc2-contacts" version = "0.2.2" @@ -3986,17 +3963,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-core-data" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" -dependencies = [ - "bitflags 2.10.0", - "objc2 0.6.3", - "objc2-foundation 0.3.2", -] - [[package]] name = "objc2-core-foundation" version = "0.3.2" @@ -4017,13 +3983,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" dependencies = [ "bitflags 2.10.0", - "block2 0.6.2", "dispatch2", - "libc", "objc2 0.6.3", "objc2-core-foundation", "objc2-io-surface", - "objc2-metal 0.3.2", ] [[package]] @@ -4035,17 +3998,7 @@ dependencies = [ "block2 0.5.1", "objc2 0.5.2", "objc2-foundation 0.2.2", - "objc2-metal 0.2.2", -] - -[[package]] -name = "objc2-core-image" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" -dependencies = [ - "objc2 0.6.3", - "objc2-foundation 0.3.2", + "objc2-metal", ] [[package]] @@ -4060,48 +4013,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-core-services" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583300ad934cba24ff5292aee751ecc070f7ca6b39a574cc21b7b5e588e06a0b" -dependencies = [ - "bitflags 2.10.0", - "block2 0.6.2", - "dispatch2", - "libc", - "objc2 0.6.3", - "objc2-core-foundation", - "objc2-security", -] - -[[package]] -name = "objc2-core-text" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d" -dependencies = [ - "bitflags 2.10.0", - "objc2 0.6.3", - "objc2-core-foundation", - "objc2-core-graphics", -] - -[[package]] -name = "objc2-core-video" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" -dependencies = [ - "bitflags 2.10.0", - "block2 0.6.2", - "objc2 0.6.3", - "objc2-core-foundation", - "objc2-core-graphics", - "objc2-io-surface", - "objc2-metal 0.3.2", -] - [[package]] name = "objc2-encode" version = "4.1.0" @@ -4128,8 +4039,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.10.0", - "block2 0.6.2", - "libc", "objc2 0.6.3", "objc2-core-foundation", ] @@ -4179,17 +4088,6 @@ dependencies = [ "objc2-foundation 0.2.2", ] -[[package]] -name = "objc2-metal" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" -dependencies = [ - "bitflags 2.10.0", - "objc2 0.6.3", - "objc2-foundation 0.3.2", -] - [[package]] name = "objc2-quartz-core" version = "0.2.2" @@ -4200,7 +4098,7 @@ dependencies = [ "block2 0.5.1", "objc2 0.5.2", "objc2-foundation 0.2.2", - "objc2-metal 0.2.2", + "objc2-metal", ] [[package]] @@ -4210,14 +4108,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" dependencies = [ "bitflags 2.10.0", - "block2 0.6.2", - "libc", "objc2 0.6.3", "objc2-core-foundation", - "objc2-core-graphics", - "objc2-core-video", "objc2-foundation 0.3.2", - "objc2-metal 0.3.2", ] [[package]] @@ -4264,9 +4157,9 @@ dependencies = [ "bitflags 2.10.0", "block2 0.5.1", "objc2 0.5.2", - "objc2-cloud-kit 0.2.2", - "objc2-core-data 0.2.2", - "objc2-core-image 0.2.2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image", "objc2-core-location", "objc2-foundation 0.2.2", "objc2-link-presentation", diff --git a/justfile b/justfile index 41279c84..1d200ab5 100644 --- a/justfile +++ b/justfile @@ -3,7 +3,7 @@ export RUST_BACKTRACE := "full" fmt: test -z "$(rg 'eyre!' --type rust)" || (echo "eyre! macro not allowed"; false) test -z "$(rg 'dbg!' --type rust)" || (echo "dbg! macro not allowed"; false) - test -z "$(rg 'println!' --type rust ./komorebi)" || (echo "println! macro not allowed"; false) + test -z "$(rg 'println!' --type rust ./komorebi/src)" || (echo "println! macro not allowed"; false) cargo +stable clippy prettier --write README.md nix fmt diff --git a/komorebi-bar/Cargo.toml b/komorebi-bar/Cargo.toml index fb6bc50f..52164258 100644 --- a/komorebi-bar/Cargo.toml +++ b/komorebi-bar/Cargo.toml @@ -27,8 +27,11 @@ netdev = "0.40" num = "0.4" num-derive = "0.4" num-traits = "0.2" -objc2 = "0.6" -objc2-app-kit = "0.3" +objc2 = { version = "0.6", default-features = false, features = ["std"] } +objc2-app-kit = { version = "0.3", default-features = false, features = [ + "std", + "NSApplication", +] } parking_lot = { workspace = true } random_word = { version = "0.5", features = ["en"] } reqwest = { version = "0.12", features = ["blocking"] } diff --git a/komorebi/Cargo.toml b/komorebi/Cargo.toml index 3fc1fee0..0597442d 100644 --- a/komorebi/Cargo.toml +++ b/komorebi/Cargo.toml @@ -23,18 +23,82 @@ ed25519-dalek = "2" hotwatch = { workspace = true } lazy_static = { workspace = true } nanoid = "0.4" -objc2 = "0.6" -objc2-app-kit = "0.3" -objc2-application-services = "0.3" -objc2-core-foundation = { version = "0.3", features = [ - "CFDictionary", - "CFString", +objc2 = { version = "0.6", default-features = false, features = ["std"] } +objc2-app-kit = { version = "0.3", default-features = false, features = [ + "std", + "objc2-quartz-core", + "libc", + "NSApplication", + "NSWindow", + "NSView", + "NSColor", + "NSAlert", + "NSButton", + "NSControl", + "NSResponder", + "NSWorkspace", + "NSRunningApplication", + "NSScreen", + "NSEvent", + "NSGraphics", + "NSWindowRestoration", +] } +objc2-application-services = { version = "0.3", default-features = false, features = [ + "std", + "libc", + "HIServices", + "AXUIElement", + "AXValue", + "AXError", + "AXActionConstants", + "AXAttributeConstants", + "AXNotificationConstants", + "Accessibility", +] } +objc2-core-foundation = { version = "0.3", default-features = false, features = [ + "std", + "CFString", + "CFArray", + "CFDictionary", + "CFNumber", + "CFRunLoop", + "CFMachPort", + "CFCGTypes", +] } +objc2-core-graphics = { version = "0.3", default-features = false, features = [ + "std", + "alloc", + "CGWindow", + "CGDirectDisplay", + "CGDisplayConfiguration", + "CGEvent", + "CGEventSource", + "CGEventTypes", + "CGColor", + "CGError", + "CGRemoteOperation", + "CGGeometry", +] } +objc2-foundation = { version = "0.3", default-features = false, features = [ + "std", + "NSString", + "NSDictionary", + "NSBundle", + "NSURL", + "NSValue", + "NSGeometry", + "NSNotification", + "NSDistributedNotificationCenter", + "NSRunLoop", + "NSDate", + "NSKeyValueCoding", +] } +objc2-quartz-core = { version = "0.3", default-features = false, features = [ + "std", + "objc2-core-foundation", + "CALayer", + "CATransaction", ] } -objc2-core-graphics = { version = "0.3", features = ["CGWindow", "alloc"] } -objc2-core-services = "0.3" -objc2-core-video = "0.3" -objc2-foundation = "0.3" -objc2-quartz-core = "0.3" parking_lot = { workspace = true } pastey = { workspace = true } regex = "1"