Swift @_assemblyVision
Karl (via Ron Avitzur):
There is a super-hidden feature in the compiler which gives you insight in to all kinds of optimisation decisions: such as the cost-benefit calculations for inlining, where exclusivity is enforced, where ARC operations happen, which generic specialisations get generated and which calls get devirtualised.
[…]
To use it, add the
@_assemblyVision
attribute to a function, and build in release mode (or@_semantics("optremark")
on a pre-5.6 compiler.
The first is called opt remarks. “opt remarks” shows the decisions the optimizer is making (e.x.: did I specialize this, did I inline this/etc).
The second is something that I invented called “Assembly Vision”. This is the thing that is telling you where the ARC/exclusivity checks/runtime casts. Assembly Vision also enables the other form of normal opt-remarks since that information can be useful when determining where/why ARC is there. The idea is to make it so that instead of having to read the assembly, one can have vision on approximately where these calls are so you don’t have to read the assembly yourself.
[…]
The concept came from me trying to automate how I optimize Swift code as a compiler engineer so that other engineers who aren’t compiler people can be just as effective.
This looks incredibly useful.
Previously:
- Swift 5.6 Released
- Roadmap for Improving Swift Performance Predictability
- Lists of Swift Attributes
- Swift 5 Exclusivity Enforcement