Component.name optimized: replace String(describing:) with _typeName - #489
ChrisBenua wants to merge 1 commit into
Conversation
|
@rudro Hi, Rudro! This PR will significantly improve performance for large apps. If this PR matches your expectations, I'd appreciate your guidance on how we can proceed with merging the PR. Thanks in advance! |
| let parts = fullyQualifiedSelfName.components(separatedBy: ".") | ||
| return parts.last ?? fullyQualifiedSelfName | ||
| }() | ||
| private lazy var name: String = _typeName(type(of: self), qualified: false) |
There was a problem hiding this comment.
This is wonderful, but it uses a private API. Up to the maintainers to decide if that's ok
There was a problem hiding this comment.
It's not truly private API. This function is public but not documented.
Moreover, it can be accessed indirectly by calling regular string interpolation. Like "\(type(of: self))"
|
We hit exactly this in a large app and can confirm the impact with a profile. Setup: Xcode 26.4, iPhone 17 Pro simulator (iOS 26.4), Debug build, Time Profiler + os_signpost intervals around the container getters. Before the patch: building one root-level object that transitively creates ~47 distinct After applying this change locally: the same interval takes 156 ms, and a first-time Root cause matches the PR description: One note on behavior parity, checked with a small test: for top-level and nested classes Would be great to get this in — @rudro @alanzeino, is there anything blocking a review? |
Previously,
String(describing: self)was used to get fully qualified name (including module name).But using
String(describing: self)to get type name is extremely ineffective (see #486 and swiftlang/swift#77369). In the endString(describing:)calls_typeName(:qualified:)function. Also, if we passqualified: false, we don't need to do any splitting workPrevious callstack when using
String(describing:):