mamift / LinqToXsdCore

LinqToXsd ported to .NET Core (targets .NET Standard 2 for generated code and .NET Core 3.1, .NET 5+ for the code generator CLI tool).
Microsoft Public License
41 stars 15 forks source link

Cache XNames #23

Closed jods4 closed 3 years ago

jods4 commented 3 years ago

Fixes #19

This contains two commits.

The first caches XName lookups for ClrPropertyInfo. This replaces the codegen of 4 XName.Get calls with a single one: (1) getter, (2) setter, (3) code model in ctor, (4) local types dictionary. (1) and (2) are esp. interesting because they can be in hot paths if you're processing a lot of large documents.

The second caches the single IXMetaData.SchemaName lookup. This one is called a lot during document processing so it's worth avoiding the expensive XName lookup.

One could try to improve the codegen further by reusing the SchemaName cache for ClrPropertyInfo or getting rid of the XName lookups in the global types dictionary. Those tasks are more complex and have virtually no runtime benefit so I stopped here.

For your convenience, I have attached a before/after of one of my schemas. test.zip

jods4 commented 3 years ago

@mamift Before you do a release, I'm gonna fix a bug blunder in this PR!! The caching fields are declared as string, they should be XName of course! I'll do a PR to fix that today.