Skip to content

Commit 70109c4

Browse files
Add JIT notes
1 parent f06b822 commit 70109c4

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

release-notes/10.0/preview/preview1/runtime.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,49 @@
88

99
- [What's new in .NET 10](https://learn.microsoft.com/dotnet/core/whats-new/dotnet-10/overview) documentation
1010

11-
## Feature
11+
## Array Interface Method Devirtualization
1212

13-
This is something about the feature.
13+
Reducing the abstraction overhead of popular language features is one of the code generation team's [focus areas](https://github.com/dotnet/runtime/issues/108988) for .NET 10. In pursuit of this goal, we have expanded the JIT's ability to devirtualize method calls to cover array interface methods.
14+
15+
Consider the C-style approach of looping over an array:
16+
17+
```csharp
18+
static int Sum(int[] array)
19+
{
20+
int sum = 0;
21+
for (int i = 0; i < array.Length; i++)
22+
{
23+
sum += array[i];
24+
}
25+
return sum;
26+
}
27+
```
28+
29+
This code shape is easy for the JIT to optimize, mainly because there aren't any virtual calls to reason about. Instead, the JIT can focus on removing bounds checks on the array access, and applying the loop optimizations we added in .NET 9. Let's tweak the above example to add some virtual calls:
30+
31+
```csharp
32+
static int Sum(int[] array)
33+
{
34+
int sum = 0;
35+
IList<int> temp = array;
36+
foreach (var num in temp)
37+
{
38+
sum += num;
39+
}
40+
return sum;
41+
}
42+
```
43+
44+
The type of the underlying collection is clear, and the JIT should be able to transform this snippet into the first one. However, array interfaces are implemented differently from "normal" interfaces, such that the JIT does not know how to devirtualize them. This means the enumerator calls in the for-each loop remain virtual, blocking multiple optimizations: inlining, stack allocation, and others.
45+
46+
In Preview 1, the JIT can now devirtualize and inline array interface methods, thanks to work in [#108153](https://github.com/dotnet/runtime/pull/108153) and [#109209](https://github.com/dotnet/runtime/pull/109209). This is the first of many steps we will be taking to achieve performance parity between the above implementations, as detailed in our [de-abstraction plans](https://github.com/dotnet/runtime/issues/108913) for .NET 10.
47+
48+
## Stack Allocation of Arrays of Value Types
49+
50+
In .NET 9, the JIT gained the ability to allocate objects on the stack, when the object is guaranteed to not outlive its parent method. Not only does stack allocation reduce the number of objects the GC has to track, but it also unlocks other optimizations: For example, after an object has been stack-allocated, the JIT can consider replacing it entirely with its scalar values. Because of this, stack allocation is key to reducing the abstraction penalty of reference types.
51+
52+
In Preview 1, thanks to [contributions](https://github.com/dotnet/runtime/pull/104906) from @hez2010, the JIT will now allocate arrays of value types on the stack when it can make the same lifetime guarantees described above. Among other [stack allocation enhancements](https://github.com/dotnet/runtime/issues/104936), we plan to expand this ability to arrays of reference types in the coming previews.
53+
54+
## AVX10.2 Support
55+
56+
Preview 1 enables support for the Advanced Vector Extensions (AVX) 10.2 for x64-based processors, thanks to [contributions](https://github.com/dotnet/runtime/pull/111209) from @khushal1996. .NET developers can try out the new intrinsics available in the `System.Runtime.Intrinsics.X86.Avx10v2` class once capable hardware is available. In the next several previews, we plan to further incorporate AVX10.2 support into the JIT's emitter to take full advantage of the instruction set's features.

0 commit comments

Comments
 (0)