Check the answer at the following link: Delegate changes in caching behavior in Roslyn
Basically what has changed, and I quote @Yuzal from a related answer:
"In Roslyn, the delegate caching behavior was changed. Previously, like any lambda expression that did not commit variables, it was compiled into a static method on the call site. Roslin changed this behavior. Now any lambda that captures variables or not is converted to a class display: "
And according to the display class, he had in mind the generated closed private class, inside which the instance method, called by the action delegate, is encapsulated.
Why was the change made? Quoting @Kevin Pilch-Bisson (member of C # ID team):
The reason for this is faster, because delegate calls are optimized for instance methods and have room for a stack for them. To call the static method, they must shift parameters around.
So basically the commentary itself explains. The behavior you see in the above example is that they noticed that if an Action delegate is invoked by instance methods, it is faster than calling static methods, regardless of whether the lambda captures variables or not.
source share