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

Improve profiled casts #90594

Merged
merged 1 commit into from
Aug 15, 2023
Merged

Improve profiled casts #90594

merged 1 commit into from
Aug 15, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 15, 2023

For profiled casts, we currently give up on negative cases (when profiled type is never of the casted interface). This PR fixes that, benchmark:

object _obj = 42;

[Benchmark]
public bool IsInterface() => _obj is ICollection or IDisposable;
|      Method |     Mean |    Error |   StdDev |
|------------ |---------:|---------:|---------:|
| IsInterface | 13.80 ns | 1.975 ns | 0.108 ns | Main
| IsInterface |  0.39 ns | 0.029 ns | 0.002 ns | PR

(with DOTNET_JitProfileCasts=1)

Basically, we expand it as obj == null ? null : (obj.GetType() == typeof(int) ? null : helperCall()) (for each isinst)

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 15, 2023
@ghost ghost assigned EgorBo Aug 15, 2023
@ghost
Copy link

ghost commented Aug 15, 2023

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

Issue Details

For profiled casts, we currently give up on negative cases (when profiled type is never of the casted interface). This PR fixes that, benchmark:

object _obj = 42;

[Benchmark]
public bool IsInterface() => _obj is ICollection or IDisposable;
Method Mean Error StdDev
IsInterface 13.80 ns 1.975 ns 0.108 ns
IsInterface 0.39 ns 0.0287 ns 0.0016 ns

Basically, we expand it as _obj.GetType() == typeof(int) ? null : helperCall (for each isinst)

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Aug 15, 2023

/azp run runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress

@EgorBo EgorBo marked this pull request as ready for review August 15, 2023 14:52
@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@EgorBo
Copy link
Member Author

EgorBo commented Aug 15, 2023

@AndyAyersMS PTAL, small change to the "not-yet-enabled-by-default" cast profiling.

@EgorBo
Copy link
Member Author

EgorBo commented Aug 15, 2023

Failures are #90593

@EgorBo EgorBo merged commit 4e166f2 into dotnet:main Aug 15, 2023
@EgorBo EgorBo deleted the mustnot-casts branch August 15, 2023 20:41
@ghost ghost locked as resolved and limited conversation to collaborators Sep 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants