Skip to content

Optimize macros - #81

Merged
maleadt merged 5 commits into
mainfrom
tb/opt
Aug 13, 2026
Merged

maleadt merged 5 commits into
mainfrom
tb/opt

Conversation

@maleadt

@maleadt maleadt commented Aug 13, 2026

Copy link
Copy Markdown
Member

No description provided.

maleadt and others added 4 commits August 13, 2026 14:21
The return type of an @objc call (and the object type of an
@autoproperty) was resolved with Base.eval, which lowers and interprets
the expression at top level, costing ~100µs whenever the type is a
non-trivial expression like id{NSString}. Resolve the common shapes
(names, qualified names, curly applications) by walking the AST
directly, falling back to eval for anything else.

Reduces @objc expansion time by ~35% for Expr return types.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@objcwrapper and @autoproperty emitted '@static if !is_available(...)'
blocks, whose condition @static evaluates with Core.eval on every
downstream expansion — ~100µs each, even with no availability
annotation. The macros already hold the availability as a value, so
perform the check directly and only emit the throw when unavailable;
the timing is identical since @static would have evaluated at the same
expansion.

Reduces @objcwrapper expansion time by ~40%, and @objcproperties by
~120µs per property.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Every @objcwrapper emitted identical Base.getproperty/setproperty!/
propertynames forwarders for its class. Lowering a method definition
costs ~300µs, so these three accounted for ~20% of the total top-level
cost of a wrapper definition. Define them once on Object instead;
typeof(object) is concrete after inlining, so property inference and
constant folding are unaffected.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maleadt
maleadt marked this pull request as draft August 13, 2026 13:23
@maleadt

maleadt commented Aug 13, 2026 •

Copy link
Copy Markdown
Member Author

Speeds up things locally, but curiously slows down Metal.jl. So marked draft again.

try_resolve_type constructed Some(x) and used map/broadcast over the
resolved values, minting Some{Type{NewClass}} and related specializations
for every newly defined wrapper class. Each new class thus forced fresh
inference of the widening/broadcast machinery (~9ms per class), more than
undoing the savings of resolving types without eval: expanding a
wrapper+properties block went from 11ms to 18ms.

Use @nospecialize, Some{Any}, and a Vector{Any} loop so resolution
compiles once, and restrict the getproperty branch to module lookups
(anything else falls back to eval as before). Brings the block back
down to 9.3ms, now genuinely faster than before the resolver.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@maleadt
maleadt marked this pull request as ready for review August 13, 2026 13:34
@maleadt
maleadt merged commit c399b4b into main Aug 13, 2026
12 checks passed
@maleadt
maleadt deleted the tb/opt branch August 13, 2026 13:56
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