Skip to content

Commit b24bc11

Browse files
Merge pull request #42841 from amanasifkhalid/fix-stack-alloc-example
2 parents a512438 + e5b2612 commit b24bc11

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

docs/core/whats-new/dotnet-9/runtime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ ret
354354

355355
The calls to `CORINFO_HELP_NEWSFAST` are the heap allocations for the boxed integer arguments. Also, notice that there isn't any call to `Compare`; the compiler decided to inline it into `RunIt`. This inlining means the boxes never "escape." In other words, throughout the execution of `Compare`, it knows `x` and `y` are actually integers, and they can be safely unboxed them without affecting the comparison logic.
356356

357-
Starting in .NET 9, the 64-bit compiler allocates unescaped boxes on the stack, which unlocks several other optimizations. In this example, not only does the compiler avoid the heap allocations, but it also evaluates the expressions `x.Equals(y)` and `result ? 0 : 100` at compile time. Here's the updated assembly:
357+
Starting in .NET 9, the 64-bit compiler allocates unescaped boxes on the stack, which unlocks several other optimizations. In this example, the compiler now omits the heap allocations, but because it knows `x` and `y` are 3 and 4, it can also omit the body of `Compare`; the compiler can determine `x.Equals(y)` is false at compile time, so `RunIt` should always return 100. Here's the updated assembly:
358358

359359
```al
360360
mov eax, 100

0 commit comments

Comments
 (0)