Yes they are different! - but I'm not sure how quantifiably different their performance is!
Umbraco.Field is a legacy approach for writing out property values, dictionary items, going way back before MVC was possible in Umbraco. It has lots of nice little helpers and falbacks for writing out property values, eg convertLineBreaks, removeParagraphTags, formatAsDate etc
Whereas Model.Content.GetPropertyValue is just writing out the value of a property from the current page's IPublishedContent Model, introduced when Umbraco became more MVC like...
I'd expect Model.Content.GetPropertyValue to be quicker, but the best way to know would be to use the MiniProfiler to measure how each approach performs on your site:
Umbraco.Field vs Model.Content.GetPropertyValue
Hi guys, quick question,
is there any difference in the performance between those 2?
Umbraco.Field("alias") & Model.Content.GetPropertyValue("alias")
Thanks in advance
Hi Thomas
Yes they are different! - but I'm not sure how quantifiably different their performance is!
Umbraco.Field is a legacy approach for writing out property values, dictionary items, going way back before MVC was possible in Umbraco. It has lots of nice little helpers and falbacks for writing out property values, eg convertLineBreaks, removeParagraphTags, formatAsDate etc
You can see how it's implemented here:
https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/UmbracoComponentRenderer.cs#L223
Whereas Model.Content.GetPropertyValue is just writing out the value of a property from the current page's IPublishedContent Model, introduced when Umbraco became more MVC like...
https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/PublishedContentExtensions.cs#L274
I'd expect Model.Content.GetPropertyValue to be quicker, but the best way to know would be to use the MiniProfiler to measure how each approach performs on your site:
https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#miniprofiler
regards
Marc
Cheers Marc, I had no idea about the MiniProfiler, looks cool :)
is working on a reply...