Reduce usage of LINQ in constructor selection#18
Merged
jvandertil merged 2 commits intoReflectionMagic:masterfrom May 29, 2018
Merged
Reduce usage of LINQ in constructor selection#18jvandertil merged 2 commits intoReflectionMagic:masterfrom
jvandertil merged 2 commits intoReflectionMagic:masterfrom
Conversation
47425c8 to
dfa4e70
Compare
Improves performance in benchmarks by 200-600%
dfa4e70 to
7f05609
Compare
Improves performance by roughly 6%
Collaborator
Author
|
Removing the intermediate array improves allocations and run time slightly (~5%). BenchmarkDotNet=v0.10.14, OS=Windows 10.0.17134
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=2.1.201
[Host] : .NET Core 1.1.8 (CoreCLR 4.6.26328.01, CoreFX 4.6.24705.01), 64bit RyuJIT
DefaultJob : .NET Core 1.1.8 (CoreCLR 4.6.26328.01, CoreFX 4.6.24705.01), 64bit RyuJIT
|
davidebbo
approved these changes
May 27, 2018
Collaborator
davidebbo
left a comment
There was a problem hiding this comment.
Nice perf analysis!
Though I'm a bit surprised that the LINQ code would be that much more inefficient. It seems that it should be making roughly the same calls. But I guess the numbers don't lie :)
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.
The current implementation uses a LINQ based approach for selecting a constructor to work around the issue of not having the correct overload for Activator.CreateInstance() available.
This is allocating quite a bit of garbage and is not ideal as can be seen below:
This represents a 200-600% increase of performance and a likewise reduction of allocations. Using reflection remains slow ofcourse.
Also fixes #19.