Skip to content

Disable OSR by default - #3201

Merged
timcassell merged 1 commit into
masterfrom
disable-osr
Jul 26, 2026
Merged

timcassell merged 1 commit into
masterfrom
disable-osr

Conversation

@timcassell

@timcassell timcassell commented Jul 18, 2026 •

Copy link
Copy Markdown
Collaborator

Avoids the runtime bug of duplicated instrumented tiers when OSR is enabled to reduce time spent in the JIT stage with out-of-process CoreCLR toolchains with the default run strategy (#3143 (comment)). I think it should not affect the complete tier1 codegen. cc @AndyAyersMS @EgorBo

@timcassell
timcassell merged commit b2d9eba into master Jul 26, 2026
21 checks passed
@timcassell timcassell added this to the v0.16.0 milestone Jul 26, 2026
@timcassell
timcassell deleted the disable-osr branch July 26, 2026 23:18
lahma added a commit to quartznet/quartznet that referenced this pull request Nov 18, 2026
…ds what runtime async costs and why it stays on

BenchmarkDotNet 0.16 sets TC_OnStackReplacement=0 and TC_CallCountingDelayMs=0 in every process it starts
for a non-ColdStart job (dotnet/BenchmarkDotNet#3201). The comparison jobs set both back to the runtime's
defaults, and each process reports them. Putting OSR back took the suspending row's .NET 10 job from 2.5 to
1.8 us a firing; the no-op rows moved by 5 % or less.

The benchmark README's "BenchmarkDotNet 0.16, out of process (2026-11-18)" re-measures the 2026-11-17 legs
out of process. On the suspending row, Quartz's runtime-async asset allocates about 450 bytes more per
firing (+15 %) and takes about 3 % less time. On the no-op rows the bytes are the same.

maintainers/architecture.md, "Target frameworks", records the maintainer's decision to keep runtime async on
in 4.8, its reasons, and what turning it off takes.

Refs #4214

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lahma added a commit to quartznet/quartznet that referenced this pull request Nov 18, 2026
…ds what runtime async costs and why it stays on

BenchmarkDotNet 0.16 sets TC_OnStackReplacement=0 and TC_CallCountingDelayMs=0 in every process it starts
for a non-ColdStart job (dotnet/BenchmarkDotNet#3201). The comparison jobs set both back to the runtime's
defaults, and each process reports them. Putting OSR back took the suspending row's .NET 10 job from 2.5 to
1.8 us a firing; the no-op rows moved by 5 % or less.

The benchmark README's "BenchmarkDotNet 0.16, out of process (2026-11-18)" re-measures the 2026-11-17 legs
out of process. On the suspending row, Quartz's runtime-async asset allocates about 450 bytes more per
firing (+15 %) and takes about 3 % less time. On the no-op rows the bytes are the same.

maintainers/architecture.md, "Target frameworks", records the maintainer's decision to keep runtime async on
in 4.8, its reasons, and what turning it off takes.

Refs #4214

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AndyAyersMS

Copy link
Copy Markdown
Member

@timcassell Sorry I didn't see this notification earlier.

Disabling OSR is giving misleading results. This is not something most users do when deploying their apps. We have already had one such report.

Without OSR methods that have loops essentially bypass tiering, so code quality is also adversely impacted.

I think we need to find some other way to solve the problem that disabling OSR is solving.

@timcassell

Copy link
Copy Markdown
Collaborator Author

Thanks @AndyAyersMS. Quick check on the mechanism: as far as I can tell from the source, with TC_OnStackReplacement=0 and TC_QuickJitForLoops still at its default of 1, loop methods aren't switched to optimized. They stay in tier0 without patchpoints and tier up through call counting. Is that right, or is there another path I'm missing? Could you link the report you mentioned?

I think we need to find some other way to solve the problem that disabling OSR is solving.

The duplicated tiers will need to be fixed in the JIT. We can revert this, but it will result in the JIT stage taking 50% longer, which I know is significant for dotnet/performance.

@AndyAyersMS

Copy link
Copy Markdown
Member

They can tier up if called enough and if the app makes it out of "startup mode", but that can take a long time if each call to the benchmark method invokes a long-runing loop.

dotnet/runtime#137275 is the example reported to us.

We have been living with the duplicate tiers for a while in dotnet/performance. Was that the main motivation for the change...?

@timcassell

Copy link
Copy Markdown
Collaborator Author

They can tier up if called enough and if the app makes it out of "startup mode", but that can take a long time if each call to the benchmark method invokes a long-runing loop.

We also disable "startup mode" by default.

dotnet/runtime#137275 is the example reported to us.

I see, it causes a side-effect de-optimization for someone starting an infinite loop worker outside of the benchmark method. That's reason enough to revert this.

We have been living with the duplicate tiers for a while in dotnet/performance. Was that the main motivation for the change...?

Yes. Before the JIT stage was updated to count tiers, dotnet/performance had to make educated guesses for individual benchmarks and force more warmup iterations to get to tier 1. Since it now uses the new JIT stage, all benchmarks are watched and those extra warmups were eliminated. But because of that duplicated tier bug, the JIT stage can't know whether any callees of the watched method are OSR'd, so it conservatively runs extra iterations to nudge that final tier-up.

timcassell added a commit that referenced this pull request Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants