Skip to content

Conversation

@ChrisBenua
Copy link

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 end String(describing:) calls _typeName(:qualified:) function. Also, if we pass qualified: false, we don't need to do any splitting work

Previous callstack when using String(describing:):

@CLAassistant
Copy link

CLAassistant commented Jan 31, 2026

CLA assistant check
All committers have signed the CLA.

@ChrisBenua
Copy link
Author

@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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wonderful, but it uses a private API. Up to the maintainers to decide if that's ok

Copy link
Author

@ChrisBenua ChrisBenua Jan 31, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))"

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.

3 participants