Skip to content

Conversation

@andersjonsson
Copy link
Collaborator

@andersjonsson andersjonsson commented Mar 4, 2025

Proof-of-concept-branch with additional performance work

Right now this is only used for reading the Request message. If it is going to be used for the Response message I have to figure out how this relates to CustomMessage. Should I merge the two implementations? Probably...

This branch uses a custom implementation of Message to make working with it more efficient. I also had to implement a custom XmlReader since the one returned by XDocument.GetReader() doesn't support binary data.

All tests pass, but nasty edge case bugs are still possible.

develop

Method LoopNum Mean Error StdDev Gen0 Allocated
EmptyTask 100 1.456 ms 0.0474 ms 0.0123 ms 261.7188 1.05 MB
Echo 100 8.745 ms 0.6351 ms 0.1649 ms 1656.2500 6.64 MB

This branch

Method LoopNum Mean Error StdDev Gen0 Gen1 Allocated
EmptyTask 100 1.550 ms 0.0965 ms 0.1112 ms 263.6719 1.9531 1.05 MB
Echo 100 7.110 ms 0.0646 ms 0.0718 ms 1187.5000 31.2500 4.82 MB

@andersjonsson andersjonsson marked this pull request as ready for review March 10, 2025 10:13
@andersjonsson
Copy link
Collaborator Author

andersjonsson commented Mar 10, 2025

@akshaybheda I know you've asked about performance before. Do you have a good scenario for doing some benchmarks on this? Seems to me that the perf is better but I'd like to be sure that it also applies to a real scenario.

@akshaybheda
Copy link
Contributor

Let me find some time and do some testing around this

@andersjonsson andersjonsson changed the title Implement custom message Implement custom message class Mar 10, 2025
@akshaybheda
Copy link
Contributor

This branch has slightly better performance than the latest version 1.2.0
Latest version

image

Your branch with changes
image

{
public class XDocumentXmlReader : XmlReader
{
private readonly XDocument _document;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never used

if (supportXmlDictionaryReader)
{
reader = XmlDictionaryReader.CreateTextReader(ms, readEncoding, ReaderQuotas, dictionaryReader => { });
using (var xdReader = XmlDictionaryReader.CreateTextReader(stream, readEncoding, ReaderQuotas, dictionaryReader => { }))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: you can simplify the using

Copy link
Contributor

@akshaybheda akshaybheda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did look at some of the changes and added some comments

@andersjonsson
Copy link
Collaborator Author

Thank you for taking the time.
I was hoping for a more clear performance win, but I'll take it :)

I also managed to get ParsedMessage working for the response, which resulted in higher memory usage and no speed improvement, so I'll give up on that idea.

I also tried rewriting the DefaultOperationInvoker to use expression trees, but that didn't result in a noticeable win. Maybe with more complex operations... I put that implementation in a gist, in case you want to try it out for your scenario
https://gist.github.com/andersjonsson/004925c250695a44ab7c2f0637dfd465

Rewriting the invocation code to use source generators would most likely be a big benefit, but that would be a big project and would not work for netstandard 2.0.

Copy link
Contributor

@akshaybheda akshaybheda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me

@andersjonsson andersjonsson merged commit a1f5165 into DigDes:develop Mar 18, 2025
3 checks passed
@andersjonsson andersjonsson deleted the implement-custom-message branch March 26, 2025 10:10
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.

2 participants