Gen 0 GC over-allocation issue in AB Testing

Found in

EPiServer.Marketing.Testing 2.5.12

Fixed in

EPiServer.Marketing.Testing 2.6.0


Apr 17, 2020


May 14, 2020


Closed, Fixed and tested


Environment Information

This was reported by Expert Services in a local environment (details below).

Steps to Reproduce
  1. This was observed in code, but no steps are required.
Customer Impact Statement

This is a smaller than the Gen 0 GC over-allocation issue, but noteworthy and should be easy to resolve.

Issue Description

It’s caused by the IsInSystemFolder method of the TestingContextHelper class.

public bool IsInSystemFolder()
bool flag = true;
if (this._contextHelper.HasCurrentContext())
        flag = this._contextHelper.RequestedUrl().ToLower().Contains(this._episerverHelper.GetRootPath().ToLower());
return flag;

If you notice the blue underlines above, you’ll see that this method is called within a RaiseContentEvent repeatedly within an individual request. The number of calls to this method is dependent on the volume of content being loaded, consequently.

This method calls RequestedUrl() and performs a ToLower() method on the resulting string. It does the same for GetRootPath().
You can see on the right side of perf view that these result in a large amount of memory being allocated because the multiplier is called per piece of content being loaded.
Overall, this one method is allocating 146MB of memory to Gen 0 within a 130 second timeframe. Based on an average of 3 pieces of content being loaded, we could reduce this one method’s allocations by 2/3 (or 97MB in 130 seconds) by simply storing the lowered string value within the _contextHelper and episerver helper. If there were 100 pieces of content being loaded, the reduction would be 99/100ths, and so on.