blog

.Net Core 2.1 性能改进

根据 Performance Improvements in .NET Core 2.1 一文总结。比较的对象为 .Net Core 2.0。

JIT

// 在 .net core 2.1 后不会 box
[Benchmark]
public void BoxingAllocations() => BoxingAllocations(default(Dog));

private void BoxingAllocations<T>(T thing)
{
    if (thing is IAnimal)
        ((IAnimal)thing).MakeSound();
}

private struct Dog : IAnimal
{
    public void Bark() { }
    void IAnimal.MakeSound() => Bark();
}

private interface IAnimal
{
    void MakeSound();
}

Threading

String

Formatting and Parsing

Networking

And More