Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve pipeline invocation speed #6394

Merged
merged 5 commits into from
May 31, 2022

Conversation

danielmarbach
Copy link
Contributor

@danielmarbach danielmarbach commented May 18, 2022

This is a follow-up for .NET 6 as promised in #6237

Further improve pipeline invocation speed by accessing the specific context directly instead of the interface and leveraging a bit of unsafe trickery for .NET 6

This gives us another 11-23% Improvements on top of the latest rounds for the pipeline execution and 3-22% for the exception case. Plus, it simplifies the code because there is less expression tree code available that someone has to process while reading the code.

Additionally we can get rid of the TFM specific approvals because the method call is the same on both TFMs which brings in further cleanup too.

By directly invoking the method on the concrete context instead of IExtendable a few extra squeezes out of it too that also applies for the .NET Framework version.

Pipeline execution

image

Pipeline exception

image

Pipeline warmup

Warmup is again slightly slower but that is expected since we are doing slightly more heavy lifting due to creating more generic methods during expression tree baking. It is still though in the ys area which is an acceptable price to pay.

image

…ontext directly instead of the interface and leveraging a bit of unsafe trickery for .NET 6
Copy link
Member

@DavidBoike DavidBoike left a comment

Choose a reason for hiding this comment

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

Comments for my own understanding, mostly.

var lambdaExpression = Expression.Lambda(body, outerContextParam);
expressions?.Add(lambdaExpression);
return lambdaExpression.CompileFast();
}

#if NET
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Copy link
Member

Choose a reason for hiding this comment

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

Does aggressive inlining have any effect since the method is only found via reflection? Or does this affect the compilation of the lambda expression as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was not able to find any documentation whether expression trees that point to static methods that are aggressively inlined can be properly JITed. I did run tests with and without the inlining hint and I saw 3-5% gains when I added the inlining hint. Unfortunately, I do not have the test results on the laptop I'm currently typing on, but I'm happy to share it later in case you are interested.

Copy link
Contributor

@timbussmann timbussmann left a comment

Choose a reason for hiding this comment

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

awesome!

@danielmarbach danielmarbach merged commit 5735f6d into master May 31, 2022
@danielmarbach danielmarbach deleted the more-pipeline-optimizations branch May 31, 2022 07:09
@lailabougria
Copy link
Contributor

awesome

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.

6 participants