Hello, i made a pretty quick benchmark test to see how fast invoking a ViewComponent was, and i was surprised to see that its as slow as making a 1000 classes.
Correct me if im doing something wrong, but here is my code:
@{ int totalIterations = 5; int innerIterations = 2500; for (int i = 0; i < totalIterations; ++i) { DateTime dStart = DateTime.Now; for (int j = 0; j < innerIterations; ++j) { @await Component.InvokeAsync(typeof(Foo)); //for (var u = 0; u < 1000; u++) //{ // var myClass = new MyClass(); //} } TimeSpan timeElapsed = DateTime.Now - dStart; System.Diagnostics.Debug.WriteLine("Loop ms: " + (int)timeElapsed.TotalMilliseconds); } }
In my view, im looping and invoking a viewcomponent (100% empty, and doesn't draw anything) 2500 times, and then i log it out to the output console and do it 5 times.
The output console says eg "loop ms: 59" 5 times where the millisecond value is around 34 - 59.
But then i also deleted that invoke component line, and then uncomment the for loop where its creating 1000 classes (empty classes) to see how long time that would take. And it takes around the same time.
So... invoking a viewcomponent is around 1000 times as slow as creating a class.
Can that really be true?