macro_rules! type_by_name {
($bytes:expr) => { ... };
}Expand description
Resolve a Swift type from its mangled name string.
Results are cached. Demangling walks the name, instantiates generic metadata and consults the runtime’s caches, which costs on the order of a microsecond — and the same handful of names are resolved on every view construction, so uncached it dominates the cost of building a tree. Resolve a fixed mangled name, caching in one word at the call site.
This is what the Swift compiler emits for the same job: a global per site,
a relaxed load, a null check, and the slow path taken once. The shared map
behind resolve_type_by_mangled_name has to hash the whole mangled string
under a mutex — 266 ns against the 416 the runtime call costs, so it earns
its keep, but a site that always asks for the same type should not be paying
either.
Only for names that cannot vary between calls. A site whose name is computed would cache the first answer and hand it back for every later one.