Skip to content

Commit 5e6f97a

Browse files
authored
Update method name (#42828)
1 parent ef3032f commit 5e6f97a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Consider the following snippet:
325325

326326
`Compare` is conveniently written such that if you wanted to compare other types, like strings or `double` values, you could reuse the same implementation. But in this example, it also has the performance drawback of requiring any value types that are passed to it to be *boxed*.
327327

328-
The x64 assembly code generated for `Main` is as follows:
328+
The x64 assembly code generated for `RunIt` is as follows:
329329

330330
```al
331331
push rbx
@@ -352,7 +352,7 @@ pop rbx
352352
ret
353353
```
354354

355-
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 `Main`. 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.
355+
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

357357
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:
358358

0 commit comments

Comments
 (0)