Repository navigation
Conversation
ObjectCreator.FindType resolved every schema name that is not in the entry assembly by enumerating all types of all loaded assemblies. In large applications this takes seconds and gigabytes of allocations on the first deserialization of a schema. Look up names with a namespace directly in each loaded assembly and keep the enumeration as fallback. The resolved types stay the same, including the last match winning across assemblies.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is the purpose of the change
This pull request makes resolving the generated class of a named schema in
ObjectCreator.FindTypeindependent of the number of types loaded in the process, fixing AVRO-4357. Before, every name not found in the entry assembly enumerated all types of all loaded assemblies, which takes seconds and gigabytes of allocations in large applications on the first deserialization of a schema.Assembly.GetTypein every loaded assembly.UnMangle(name)is computed once per name instead of once per type.GetTypes()throws was skipped entirely before. The direct lookup can still find a loadable type in it, so names that failed to resolve before can resolve now.This touches the same method as #3966 (AVRO-3893), which avoids the per-call closure in
FindType. The two changes are independent and should combine cleanly; I'm happy to rebase onto it if it lands first.Verifying this change
This change added tests and can be verified as follows:
ObjectCreatorTestsgains tests for resolving a full name from a non-entry assembly, for reserved words in the namespace (mangled and unmangled), and for the last loaded assembly winning when several assemblies contain the same full name. All new tests pass before and after the change.Avro.benchmarkgainsObjectCreatorBenchmarks, which resolves 50 named types with a freshObjectCreatorwhile 0 to 250,000 additional types are loaded. The benchmark can be removed if it shouldn't land in main.Run the benchmark with
dotnet run -c Release -f net10.0 -- --filter '*ObjectCreatorBenchmarks*'inlang/csharp/src/apache/benchmark, once withObjectCreator.csfrommainand once with this change.Before (
ObjectCreator.csfrommain):After (this change):
Documentation