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

Regressions in Microsoft.Extensions.DependencyInjection.GetService #54351

Closed
DrewScoggins opened this issue Jun 17, 2021 · 10 comments · Fixed by #54555
Closed

Regressions in Microsoft.Extensions.DependencyInjection.GetService #54351

DrewScoggins opened this issue Jun 17, 2021 · 10 comments · Fixed by #54555
Labels
Milestone

Comments

@DrewScoggins
Copy link
Member

Run Information

Architecture x64
OS ubuntu 18.04
Baseline a4b3772d1ada339220145843138d4c622134adeb
Compare 43b1f2c165257faae4d6a4aa886b701b63d2d5c0
Diff Diff

Regressions in Microsoft.Extensions.DependencyInjection.GetService

Benchmark Baseline Test Test/Base Test Quality Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
ServiceScopeProvider - Duration of single invocation 21.97 ns 38.43 ns 1.75 0.26
ServiceScope - Duration of single invocation 45.32 ns 60.61 ns 1.34 0.19

graph
graph
Historical Data in Reporting System

Repro

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'Microsoft.Extensions.DependencyInjection.GetService*'

Payloads

Baseline
Compare

Histogram

Microsoft.Extensions.DependencyInjection.GetService.ServiceScopeProvider


Microsoft.Extensions.DependencyInjection.GetService.ServiceScope


Docs

Profiling workflow for dotnet/runtime repository
Benchmarking workflow for dotnet/runtime repository

@DrewScoggins DrewScoggins added arch-arm64 os-linux Linux OS (any supported distro) os-windows tenet-performance Performance related issue tenet-performance-benchmarks Issue from performance benchmark arch-x64 labels Jun 17, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-DependencyInjection untriaged New issue has not been triaged by the area owner labels Jun 17, 2021
@ghost
Copy link

ghost commented Jun 17, 2021

Tagging subscribers to this area: @eerhardt, @maryamariyan
See info in area-owners.md if you want to be subscribed.

Issue Details

Run Information

Architecture x64
OS ubuntu 18.04
Baseline a4b3772d1ada339220145843138d4c622134adeb
Compare 43b1f2c165257faae4d6a4aa886b701b63d2d5c0
Diff Diff

Regressions in Microsoft.Extensions.DependencyInjection.GetService

Benchmark Baseline Test Test/Base Test Quality Baseline IR Compare IR IR Ratio Baseline ETL Compare ETL
ServiceScopeProvider - Duration of single invocation 21.97 ns 38.43 ns 1.75 0.26
ServiceScope - Duration of single invocation 45.32 ns 60.61 ns 1.34 0.19

graph
graph
Historical Data in Reporting System

Repro

git clone https://github.com/dotnet/performance.git
python3 .\performance\scripts\benchmarks_ci.py -f netcoreapp5.0 --filter 'Microsoft.Extensions.DependencyInjection.GetService*'

Payloads

Baseline
Compare

Histogram

Microsoft.Extensions.DependencyInjection.GetService.ServiceScopeProvider


Microsoft.Extensions.DependencyInjection.GetService.ServiceScope


Docs

Profiling workflow for dotnet/runtime repository
Benchmarking workflow for dotnet/runtime repository

Author: DrewScoggins
Assignees: -
Labels:

arch-arm64, arch-x64, area-Extensions-DependencyInjection, os-linux, os-windows, tenet-performance, tenet-performance-benchmarks, untriaged

Milestone: -

@eerhardt
Copy link
Member

Looks like it is caused by #53325.

cc @maryamariyan @davidfowl @pakrym

@davidfowl
Copy link
Member

bug fix > performance 😄

@maryamariyan maryamariyan added this to the 6.0.0 milestone Jun 17, 2021
@maryamariyan maryamariyan removed the untriaged New issue has not been triaged by the area owner label Jun 17, 2021
@pakrym
Copy link
Contributor

pakrym commented Jun 21, 2021

bug fix > performance 😄

Sure, but did we expect a regression from that change? Is the regression caused by the if check? Can we make it cheaper?

@davidfowl
Copy link
Member

I did yes, it's one extra branch. We should definitely see if we can make the check cheaper but I'm not sure it's worth redesigning anything over.

Maybe we can do a reference equals for the root scope check or stash a bool instead of service scope itself to avoid that comparison altogether

@pakrym
Copy link
Contributor

pakrym commented Jun 21, 2021

We should try turning IsRootScope into a readonly field.

davidfowl added a commit that referenced this issue Jun 22, 2021
- Stash a field instead of doing an equality comparison.

Fixes #54351
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 22, 2021
@ghost ghost closed this as completed in #54555 Jun 22, 2021
ghost pushed a commit that referenced this issue Jun 22, 2021
- Stash a field instead of doing an equality comparison.

Fixes #54351
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 22, 2021
@davidfowl davidfowl reopened this Jun 25, 2021
@davidfowl
Copy link
Member

We should leave this open since the change didn't have much of an impact on this code path.

@davidfowl
Copy link
Member

Looking at the actual benchmark(s) more deeply it seems like:

[Benchmark]
public IServiceScopeFactory ServiceScopeProvider() => _serviceScopeFactoryProvider.GetService<IServiceScopeFactory>();

[Benchmark]
public IServiceScope ServiceScope() => _serviceScope.CreateScope();

IServiceScopeFactory is a singleton so I wonder if this part of the change made thing worse. I would have thought that @pakrym's change here would have been a fine replacement for this but maybe avoiding the call to the runtime resolving when the value is cached is faster.

I don't get why CreateScope is slower.

@maryamariyan
Copy link
Member

The latest charts show we gained back perf numbers after PR #54732:

image

image

So this issue can be safely closed.

@pakrym
Copy link
Contributor

pakrym commented Aug 3, 2021

I think the regression is still there:
image

The avg is clearly higher.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants