Skip to content

Cache wrapped ABI pointer in InterfaceWrapperBase#249

Draft
mliberman wants to merge 1 commit into
mainfrom
max/cache-internal-abi-pointer
Draft

Cache wrapped ABI pointer in InterfaceWrapperBase#249
mliberman wants to merge 1 commit into
mainfrom
max/cache-internal-abi-pointer

Conversation

@mliberman
Copy link
Copy Markdown
Contributor

@mliberman mliberman commented Mar 6, 2026

Cache internal ABI pointer in InterfaceWrapperBase

InterfaceWrapperBase.toABI was doing an as? AnyAbiInterfaceImpl<I> dynamic cast on every call, which triggers swift_dynamicCastswift_conformsToProtocol in the Swift runtime. This caches the result at init time in a wrappedAbi property so toABI becomes a simple nil check.

Benchmark results (vs lazy-error-fix baseline, 7 runs)

Benchmark Baseline (ns) Optimized (ns) Change Speedup p-value
Object
object.in 3,998 2,560 -36.0% 1.56x *** p<0.001
Collection
collection.vector_in 4,400 2,969 -32.5% 1.48x *** p<0.001
collection.map_out 3,542 3,355 -5.3% 1.06x *** p<0.001
Weak Reference
weakref.create_resolve 17,506 14,543 -16.9% 1.20x *** p<0.001
weakref.create 6,588 5,207 -21.0% 1.26x *** p<0.001
weakref.resolve 10,519 9,022 -14.2% 1.17x ** p<0.01
Integration
integration 68,559 62,689 -8.6% 1.09x *** p<0.001

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

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