Batch loading of content area items


Working on a site with content areas with many content area items, I was profiling the site and database to improve the first load performance of the site.

I attempted to batch load all items when rendering each content area (in a CustomContentAreaRenderer, using IContentLoader.GetItems). But before even reaching my batch loading code, it turns out Episerver had already loaded each block individually and sequentially. Actually, for most of of the blocks it even called two stored procedures per content area item: netFindContentCoreDataByContentGuid and netContentDataLoad.

It would be really nice if Episerver could batch load all the blocks, when enumerating ContentArea.Items, instead of loading individually?

Or Episerver could just batch preload ContentAreaItem (calling netFindContentCoreDataByContentGuid) when calling ContentArea.Items. Then the actual content could be batch loaded in a CustomContentAreaRenderer.

Oct 29, 2019 14:40

which method(-s) you override?

Nov 02, 2019 4:59

It was ContentAreaRenderer.RenderContentAreaItems.
It accepts a list of ContentAreaItem. But the IContent of these are already individually preloaded at that stage.

Nov 02, 2019 6:52

I haven't tested this myself, just curious what if you go 1 level up and override Render() method?

Nov 02, 2019 13:53

@valdis: that doesn't make a difference.

Turns out the constructor of ContentAreaItem is loading the content (from cache or DB). And this is called when accessing the ContentArea.Items properties, which happens before reaching the methods I mentioned.

I think it would be nice if that constructor didn't preload the content item, just to check that it exists. Maybe the Items enumerator could batch preload the core data (not the complete content data) before calling the constructors.

Nov 03, 2019 6:13
This thread is locked and should be used for reference only.
* 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.