Optimize KeyExpression.Create()#444
Conversation
botinko
left a comment
There was a problem hiding this comment.
It doesn't look as it would be faster. Simple LINQ like entityType.Key.Columns.Select(CreateField).ToArray() can be optimized by .net itself better, then manually.
entityType.Columns.Where(c => c.IsPrimaryKey).OrderBy(c => c.Field.MappingInfo.Offset) still there, which looks like a primiry case.
The code becomes more complex, and the benefits are insignificant.
Is it known super-hot spot?
And I see this code in core dumps' stack traces. That means it is a hot-spot |
| fields = ar; | ||
| } | ||
| else { | ||
| List<FieldExpression> list = new(1); |
There was a problem hiding this comment.
my previous experiment showed, that it's more efficient to count array size entityType.Columns.Count(c => c.IsPrimaryKey) and allocate array of fixed size.
|
Got it. It's still not obvious without bench, that new version is significantly faster, then existing. |
|
I let AI work on this an got the following: |
|
So, my gut feeling was right, |
|
|
According to the provided benchmarks - we are struggling to optimize a couple of nanoseconds. Is it really worth the efforts? |
~20 ns and 150 bytes in most frequent case: And I started this because I saw in core dumps' stacktraces that the App is busy at this method. |
Avoid closure & reduce LINQ operations to save allocations