Add new WriteRecords benchmark and performance fix.
#2350
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.
Updates
The new benchmark measures the performance of WriteRecords given an
IEnumerable<T>records. The performance fix is to adjustObjectRecordWriterto take all expressions and put them into a single block expression that writes all fields at once, instead of combining multiple expressions into a single multi-cast delegate. This results in fewer delegate invocations since it is called per record instead of per field, and only a single delegate compile. The current benchmark runs ~15% faster with the new code.Now that delegates are not combined
RecordWriter.CombineDelegatescould be removed, though I opted not to since it is on a public class and I didn't want to break compatibility. I also noted this was added since Silverlight doesn't haveDelegate.Combineand I'm not sure if Silverlight hasExpression.Blockthough given it is out of support as of Oct 2021 I figured this was ok.Before
After
Note the CPU trace shows more samples in the after but this is due to BenchmarkDotNet having a variable number of iterations per run. The actual performance per iteration is faster

