Skip to content

Implement heuristic to prioritize reflection info in field descriptor search #59802

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

Conversation

augusto2112
Copy link
Contributor

Currently when looking for field descriptors we parse the reflection
metadata in whatever order it was registered. This patch implements a
heuristic where we try to match a new optional Name field with the
module name of the type's field descriptor we're looking for.

rdar://87889973

@augusto2112
Copy link
Contributor Author

@swift-ci test

@augusto2112 augusto2112 force-pushed the heuristic-get-field-descriptor branch from 88e8c3d to b3df5a4 Compare June 30, 2022 01:12
@slavapestov
Copy link
Contributor

The mangled type name already includes the module name. Is this for correctness or performance?

@augusto2112
Copy link
Contributor Author

augusto2112 commented Jun 30, 2022

@slavapestov performance. In lldb's case (not sure about the runtime) it can be quite expensive to normalize thousands of mangled names before finding the one we're looking for

@augusto2112 augusto2112 changed the title Implement heuristic to prioritize in field descriptor search Implement heuristic to prioritize reflection info in field descriptor search Jun 30, 2022
@augusto2112 augusto2112 requested a review from slavapestov June 30, 2022 01:18
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@slavapestov
Copy link
Contributor

it can be quite expensive to normalize thousands of mangled names before finding the one we're looking for

What does 'normalize' mean? Perhaps when loading the image we should build a hashtable or something instead? It seems unnecessary to add redundant information to the field descriptor.

@augusto2112
Copy link
Contributor Author

augusto2112 commented Jun 30, 2022

What does 'normalize' mean?

Essentially converting a mangled name with symbolic references, substitutions, etc, into a "normal" mangled name (look at normalizeReflectionName).

Perhaps when loading the image we should build a hashtable or something instead?

Building the hashtable of MangledName -> FieldDescriptor is the slow part 😆 The problem is that currently there's no way to know in what image the field descriptor is, so we parse (and cache) everything in whatever order the images were registered. If the field descriptor we're looking for happens to be near the end of that list, we parse everything else in front of it. In the app I'm profiling we normalize upwards of 20k mangled names (which takes 5+ seconds when debugging on a real device) when we're looking for only two field descriptors.

It seems unnecessary to add redundant information to the field descriptor.

We're only adding one fairly short StringRef per image (ReflectionInfo), we're not actually touching the field descriptors themselves. This shouldn't be too bad.

@augusto2112 augusto2112 force-pushed the heuristic-get-field-descriptor branch from b3df5a4 to 781feaa Compare June 30, 2022 21:43
@augusto2112 augusto2112 requested a review from mikeash June 30, 2022 22:03
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

Comment on lines 263 to 266
Found = FieldTypeInfoCache.find(*MangledName);
if (Found != FieldTypeInfoCache.end()) {
return Found->second;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

both calls to PopulateFieldTypeInfoCacheWithReflectionInfo are followed by this lookup. Should there be some function, say FindFieldDescriptor(Info, *MangledName), which searches and also handles the population/caching as an implementation detail?

@jckarter
Copy link
Contributor

Would it make sense for the Name to be a SmallVector of names, in case there are types from multiple modules present in an image?

@augusto2112
Copy link
Contributor Author

@jckarter yes I think that makes a lot of sense.

@augusto2112 augusto2112 force-pushed the heuristic-get-field-descriptor branch 2 times, most recently from 5c43c2e to 129fab7 Compare July 1, 2022 18:00
@augusto2112 augusto2112 force-pushed the heuristic-get-field-descriptor branch 2 times, most recently from 4e0e6c8 to 632d187 Compare July 1, 2022 21:44
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

@augusto2112
Copy link
Contributor Author

@swift-ci test

Currently when looking for field descriptors we parse the reflection
metadata in whatever order it was registered. This patch implements a
heuristic where we try to match a new optional Name field with the
module name of the type's field descriptor we're looking for.

rdar://87889973
@augusto2112 augusto2112 force-pushed the heuristic-get-field-descriptor branch from 632d187 to 65a9e7d Compare July 5, 2022 20:31
@augusto2112
Copy link
Contributor Author

@swift-ci smoke test

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.

5 participants