Skip to content
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

[Java.Interop.Tools.Cecil] Unroll TypeDefinitionRocks iterators. #1244

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpobst
Copy link
Contributor

@jpobst jpobst commented Aug 15, 2024

Make a few small performance related changes to TypeDefinitionRocks:

  • Calling TypeDefinitionRocks.Get[TypeAnd]BaseTypes provides a convenient API to work with, however it creates an iterator method and related generated infrastructure code, which causes a small amount of overhead. For performance sensitive hot paths, do the looping through base types at the call site instead.

This change provides a minor (3.5ms) speedup on the test case of calling HasJavaPeer on every type in Mono.Android, but we call these paths enough that it might add up.

Method Mean Error StdDev Gen0 Gen1 Gen2 Allocated
Original_HasJavaPeer 25.13 ms 0.608 ms 1.791 ms 1093.7500 1031.2500 812.5000 37.83 MB
Unrolled_HasJavaPeer 21.62 ms 0.426 ms 0.569 ms 1093.7500 1031.2500 843.7500 36.9 MB
  • Change TypeDefinitionRocks.HasJavaPeer to always exit immediately if the type is an interface, as an interface cannot have any of the listed base types.

  • Create IsSubclassOfAny and ImplementsAnyInterface method variants that can replace patterns where we iterate through base types or interfaces multiple times looking for multiple values.

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.

1 participant