Skip to content

[SwiftCompilerSources] Use interpolation instead of String(describing:) #78288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

hamishknight
Copy link
Contributor

@hamishknight hamishknight commented Dec 19, 2024

String(describing:) does a bunch of dynamic casts that can be pretty slow. Use interpolation instead, which bypasses them.

  • For swift-frontend, this brings the time taken for type-checking an empty file down from ~100ms to ~70ms.
  • For swift build, this brings the time taken for a null build down from ~600ms to ~450ms (the larger delta is presumably due to the fact that there's much more Swift code in swift-package).

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

nice!

@eeckstein
Copy link
Contributor

String interpolation ("\(cl)") would also work. It's optimized to _typeName

…g:)`

`String(describing:)` does a bunch of dynamic casts
that can be pretty slow. Use interpolation instead,
which bypasses them.

For `swift-frontend`, this brings the time taken
for type-checking an empty file down from ~100ms
to ~70ms.

For `swift build`, this brings the time taken for
a null build down from ~600ms to ~450ms (the
larger delta is presumably due to the fact that
there's much more Swift code in `swift-package`).
@hamishknight
Copy link
Contributor Author

Nice! Updated to use interpolation

@hamishknight
Copy link
Contributor Author

@swift-ci please smoke test

@hamishknight hamishknight changed the title [SwiftCompilerSources] Use _typeName instead of String(describing:) [SwiftCompilerSources] Use interpolation instead of String(describing:) Dec 19, 2024
@hamishknight hamishknight merged commit 95ae8d1 into swiftlang:main Dec 19, 2024
3 checks passed
@hamishknight hamishknight deleted the use-typename branch December 19, 2024 20:06
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.

2 participants