Repository navigation
Define one objc_traits method per wrapper class - #92
Merged
Merged
Conversation
`@objcwrapper` defined up to four trait methods per class (`objc_parent`, `is_managed_wrapper`, `check_available` and `compare_by_pointer`), and every method a package defines adds to the time it takes to load it; Metal.jl has about 2640 of them. Instead define a single `objc_traits` method returning all traits as a NamedTuple, and make the trait functions read from it. The traits are constant, so they still fold at compile time, and the trait functions remain the interface: hand-written methods for individual classes keep taking precedence. This removes about 2000 methods from Metal.jl, which loads about 50 ms faster on Julia 1.13.
maleadt
force-pushed
the
tb/objc-traits
branch
from
October 28, 2026 15:04
dd8cf0d to
d291f79
Compare
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.
@objcwrapperdefines up to four trait methods per wrapper class (objc_parent,is_managed_wrapper,check_availableandcompare_by_pointer), and every method a package defines adds to its load time: Metal.jl has about 2640 of them.This defines a single
objc_traits(::Type{X})method per class returning the traits as a NamedTuple, and makes the trait functions read from it. The traits are constant, so they still fold at compile time (generated code is unchanged), and the trait functions remain the interface: hand-written methods for individual classes keep taking precedence, which the added tests check, both directly and through behavior (property lookup through an overridden parent,==with an overridden comparison, an overridden availability check). One nuance: a broader hand-written trait method can now win where a macro-generated exact per-class method used to outrank it.For Metal.jl this removes about 2000 methods, and loads its package image about 50 ms faster on Julia 1.13 (within noise on 1.12).