Skip to content

[5.9][Runtime] Fast lookups of Concurrency types with standard manglings. #66175

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

Conversation

mikeash
Copy link
Contributor

@mikeash mikeash commented May 26, 2023

Cherry-pick #66107 to release/5.9.

Have the Concurrency runtime register a struct containing pointers to all of its type descriptors with standard manglings. Then have the runtime use that struct to quickly look up those types, instead of using the standard, slower type lookup code.

rdar://109783861
(cherry picked from commit dfd313c)

…ngs.

Have the Concurrency runtime register a struct containing pointers to all of its type descriptors with standard manglings. Then have the runtime use that struct to quickly look up those types, instead of using the standard, slower type lookup code.

rdar://109783861
(cherry picked from commit dfd313c)
@mikeash mikeash requested a review from a team as a code owner May 26, 2023 16:51
@tbkka
Copy link
Contributor

tbkka commented May 26, 2023

Q: What happens if the app has linked one of the back-deployment Concurrency libraries? (CC: @etcwilde )

@mikeash
Copy link
Contributor Author

mikeash commented May 26, 2023

Nothing happens, we link the back-deployment libraries such that we always load the OS library instead if it's present.

If you mean the compatibility libraries (we get those mixed up a lot), they'll be loaded, but as long as it doesn't redefine any of the types involved, everything will still work fine. I don't think we'd ever redefine the types, or that we even could.

Edit: worth noting that if the Concurrency runtime somehow fails to register these types (maybe you're running with an old one), then we gracefully fall back to the old linear scan. That does mean we'll have a harder time noticing if the registration ever stops working, but it's more robust.

Longer term, this will go away when we eventually merge the Concurrency runtime into libswiftCore.

@mikeash
Copy link
Contributor Author

mikeash commented May 26, 2023

• Description: The short-form standard manglings for Concurrency types (e.g. T means Task) currently go through the slowest of slow-path type lookups in the runtime. This change connects the type descriptors from the Concurrency runtime so that they can be looked up quickly. This can save an inordinate amount of time the first time executing code like Task.detached(priority: somePriority) {}.
• Risk: Very low. This lookup produces the same results as the slow path, just faster. We add a few dozen bytes of clean DATA and one word of dirty DATA, plus one static initializer in the Concurrency runtime, to make the connection between the two.
• Original PR: #66107
• Reviewed By: @al45tair
• Testing: The existing Swift test suite thoroughly covers these type lookups.
• Resolves: rdar://109783861

@mikeash
Copy link
Contributor Author

mikeash commented May 26, 2023

@swift-ci please test and merge

@swift-ci swift-ci merged commit 8cd5aff into swiftlang:release/5.9 May 26, 2023
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