Skip to content

Conversation

@karpinsn
Copy link

Updates

The new benchmark measures the performance of WriteRecords given an IEnumerable<T> records. The performance fix is to adjust ObjectRecordWriter to 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.CombineDelegates could 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 have Delegate.Combine and I'm not sure if Silverlight has Expression.Block though given it is out of support as of Oct 2021 I figured this was ok.

Before

OldBehavior OldTopFuncs

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
NewBehavior
NewTopFuncs

The new benchmark measures the performance of WriteRecords given an `IEnumerable<T>` records. The performance fix is to adjust `ObjectRecordWriter` to 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.CombineDelegates` could 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 have `Delegate.Combine` and I'm not sure if Silverlight has `Expression.Block` though given it is out of support as of Oct 2021 I figured this was ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant