Skip to content

Conversation

@verdie-g
Copy link
Contributor

  • Implement IEquatable<T> on Key to avoid boxing the value when using it in a dictionary. This should save one allocation per decoded field.
  • Use an array pool for constructor parameters. For .NET Standard 2.0, we could reference the nuget System.Buffers instead of adding preprocessor directives but I prefer to keep the dependencies light. This should save one allocation per decoded type.
  • Use arrays instead of Dictionary/List as their enumerator is faster and they benefits more from JIT optimizations
  • Make a TypeActivator a class. It's too large to be a struct.

Using the benchmark code from #210, it's only 1% faster but it allocates ~20% less which will put less pressure on the GC.

214.0.0.0 with GeoIP2-City-Test.mmdb

Method Mean Error StdDev Gen0 Allocated
Before 10.13 us 0.114 us 0.131 us 0.3967 6.66 KB
After 10.04 us 0.053 us 0.044 us 0.3357 5.52 KB

23.56.162.100 with GeoIP2-City.mmdb

Method Mean Error StdDev Gen0 Allocated
Before 9.897 us 0.0198 us 0.0165 us 0.3662 6.08 KB
After 9.753 us 0.1728 us 0.2185 us 0.2899 4.93 KB

I've also studied the feasibility to avoid boxing fields in the object[] parameters. It is extremely complex to do that with immutable types. The commit that implements this in System.Text.Json is 7K LOC long.

@oschwald oschwald merged commit 1e1ef7c into maxmind:main Apr 28, 2025
6 checks passed
oschwald added a commit that referenced this pull request May 5, 2025
@oschwald oschwald mentioned this pull request May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants