[SOLVED, Manual action required] Performance issue in Umbraco 9-10 when using ContentModel (or ModelsBuilder models) in custom controllers.
-"I don't need the background, just give me the files to fix this issue!"
A few months ago me and the team I was working in found an alarming issue in Umbraco 9-10. I reported the issue in the Umbraco issue tracker and it turns out that if you are using custom controllers (RenderController) and passing in a ContentModel or ModelsBuilder models to your action you will experience massive performance issues as your projects scales.
-"If you are using custom controllers with ContentModel or ModelsBuilder models you will experience massive performance issues as your projects scales."
It's not really noticeable in smaller sites, so it's easy to miss during development (which was the case for us) but as your site starts to grow in production your site will be slower and slower during rendering which in our case resulted in up to 7 seconds load time (!!) for some pages.
At first it was a bit quite on this reported issue but eventually more and more Umbracians joined in the comments section and mentioned that they experienced the same issue and eventually Kenn Jacobsen (who else?) joined the party and provides us with a solution. #h5yr. It turns out that:
-"This issue is tied to how ASP.NET Core performs validation on object graphs and a fix for this will be shipped but not until v11 as this is a breaking change!" - Kenn Jacobsen
Until then Kenn posted a few model validation classes that solves this issue by bypassing the default model validation in ASP.NET Core and these classes can be found in the already mentioned issue comments or in Kenn's pull request to Umbraco v11.
I just tried it out this morning and can confirm that adding these classes to your project and register the custom model validator solves this issue. Load time is no longer affected for larger sites and rendering is just as quick regardless if you are using CurrentPage, ContentModel or ModelsBuilder models.
-"Adding these classes to your Umbraco projects and register the custom model validator solves this issue and performance is no longer affected when using ContentModel or ModelsBuilder models in custom controllers."
Again, all credit to Kenn Jacobsen for providing us with a solution for this issue. I merely reported and share this solution to make it a little bit more accessible since GitHub comments/commits are not always the best source for documentation and bug fixes.
Hopefully this may help other Umbracians having the same issue or prevent any performance disasters in production sites.
Cheers friends! ❤️