Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues #74

Open
drpeck opened this issue Mar 6, 2018 · 4 comments
Open

Performance issues #74

drpeck opened this issue Mar 6, 2018 · 4 comments

Comments

@drpeck
Copy link

drpeck commented Mar 6, 2018

I've narrowed down a performance issue we're having with the url picker. When we request a Link, it's taking about 7ms to return the data.
content.Link.FirstOrDefault(l => l.Url != null)

I presume the delay is either the result of the internal call to Link.InitPublishedContent or the deserialisation. 7ms in isolation might not seem much, but in our footer this code is called 30 times. In our header it's called 20 times. That's 350ms delay just from accessing content cached data. Can anything be done to speed this up?

@ronaldbarendse
Copy link
Contributor

When accessing the Url property of a Link, it indeed first tries to get the IPublishedContent, but that should not be an expansive lookup if the Id and Udi are empty. It does however initialize a new UmbracoHelper for every lookup, even if it doesn't need it:

private void InitPublishedContent()
{
if (!_publishedContentInitialized)
{
_publishedContentInitialized = true;
if (UmbracoContext.Current == null)
{
return;
}
if (Udi.TryParse(_linkItem.Value<string>("udi"), out _udi))
{
_content = _udi.ToPublishedContent();
_id = _content?.Id;
}
else
{
var helper = new UmbracoHelper(UmbracoContext.Current);
// there were no Udi so let's try the legacy way
_id = _linkItem.Value<int?>("id");
if (_id.HasValue)
{
bool isMedia = _linkItem.Value<bool>("isMedia");
if (_linkItem.Value<bool>("isMedia"))
{
_content = helper.TypedMedia(_id.Value);
}
else
{
_content = helper.TypedContent(_id.Value);
}
SetUdi();
}
}
}
}

Moving this within the if (_id.HasValue) statement should be a big improvement, especially if you're using mostly external URLs.

@ronaldbarendse
Copy link
Contributor

The _udi.ToPublishedContent(); has the same flaw BTW and is depreciated (probably because of this performance issue): https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/Extensions/UdiExtensions.cs

@alindgren
Copy link

I see a fix was merged into master recently -- will this be in a release soon?

@ronaldbarendse
Copy link
Contributor

I've added some more performance improvements in PR #81. Those could also be merged in before creating a new release (although some additional testing should be done first, just to be sure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants