Removing empty block controllers for better performance

Vote:
 

I am currently looking at this interesting article: https://swapcode.wordpress.com/2018/05/16/episerver-block-performance-with-controller-vs-without-controller-vs-irendertemplate/

I am a bit of an episerver newbie, so while looking through our Episerver project I came across this block controller:

using System.Web.Mvc;
using BestDigital.Site.Models.Blocks;
using EPiServer.Web.Mvc;

namespace BestDigital.Site.Controllers
{
    public class AboutUsGridBlockController : BlockController<AboutUsGridBlock>
    {
        public override ActionResult Index(AboutUsGridBlock currentBlock)
        {
            return PartialView(currentBlock);
        }
    }
}

I this is what is considered an "empty" block controller in the article? Because if I understood it correctly all this block controller is doing is handing over data to the View?

#225638
Jul 22, 2020 11:37
Vote:
 

Yup. That controller is a good example of one you can get rid of. Doesn't do a lot for performance but everything counts...

#225639
Jul 22, 2020 11:46
Vote:
 

Thanks very much Daniel.

In theory, in such a case, all I would need to do is delete this Block Controller provided that in my View as the @model there is a reference to the actual model of this block correct?

#225640
Jul 22, 2020 11:56
Vote:
 

Exactly. A block controller like this is rarely needed.

By registering the model and partial view combination from a ViewTemplateModelRegistrator, you can skip the controller completely. I once posted this sample.

#225641
Jul 22, 2020 12:00
Vote:
 

Thanks so much Stefan, just so I understand correctly (I may have misundertood) but does this registrator go in the model for this block?

#225642
Jul 22, 2020 12:05
Stefan Holm Olsen - Jul 22, 2020 12:15
No, the registration is a class you create that inherits from an interface (see the documentation I link to in the sample).
You can place such a class in each Feature folder, if you structure your project like that.
Vote:
 

While it's certainly an improvement, based on the numbers in the blogpost, I think there are more low hanging fruits for you to try out first. I'd suggest to try with load test + profiler to see bottlenecks in your website and work on those.

#225645
Jul 22, 2020 12:32
Vote:
 

Yeah, it's a performance improvement but it's very minor. If you have performance issues on your site it's 90% because of slow integrations towards other systems based on my experience. Prefix.io is a good tool to find out which calls are made and how slow they are.

#225647
Jul 22, 2020 13:49
Vote:
 

Thank you all for the feedback. The suggested ViewTemplateModelRegistrator worked really nicely. 

#225831
Jul 28, 2020 8:44
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.