Microsoft’s Stephen Toub, a partner software engineer for .NET at Microsoft, has written a massive post detailing performance improvements in the forthcoming .NET 7, for which release is expected around November this year.
Toub’s book-length article (over 75,000 words) is based on “almost 1000 performance-impacting PRs [pull requests]”, of which he describes around 500, concluding that “it’s the fastest .NET ever.” The .NET Runtime supports Windows, Linux and macOS; Toub states that his results are recorded on Windows 11 64-bit but “aren’t Windows-specific.”
The question of how much faster is slippery. A big speed-up in some corner of the .NET just-in-time (JIT) compiler, for example, might make little difference to most applications but a big difference for code that happens to stress that part of its functionality. One of the things Toub discusses is bounds-check elimination, meaning cases where the compiler can maintain memory safety but improve performance by skipping checks for accessing memory out of the bounds of a data structure, by proving that a check is unnecessary. A performance test showed a four-times speed-up in some array operations.
Another eye-catching example is speeding performance by vectorizing data, where Toub shows example code that gives a 24x speed-up. .NET 7 has added “a very large set of cross-platform operations” based on generic Vector types, which enable this.
That raises the question: do developers need to refactor their code to get better performance, or simply upgrade from .NET 6 (or lower) to .NET 7? The answer is a bit of both. Toub gives this as a reason for writing at such length. “I want developers to learn from our own learnings and find ways to apply this new-found knowledge to their own codebases,” he said. Another factor is that typical .NET code depends on Microsoft frameworks like ASP.NET and/or Entity Framework, so if these perform better then applications based on them also benefit.
String operations are important in many operations and often relatively slow. Developers will be pleased to see that a commonly used method like IndexOf has a substantial performance increase (20x in one example), and StartsWith up to 5x faster.
Toub also covers performance on Arm64, which is increasingly important now that this processor architecture is common on the server as well as on desktop via Apple Silicon and Windows on Arm. “A huge amount of effort in .NET 7 went into making code gen for Arm64 as good or better than its x64 counterpart,” he claims.
The performance of real-world applications though depends more on the skill of developers than algorithm benchmarks. Still, getting more speed simply by upgrading the runtime is always an attractive prospect, though note that .NET 7 is not a long-term support release so many will wait for .NET 8 next year to put these changes into production.