Making theme overridden renderers more efficient

Making theme overridden renderers more efficient

by Tim Hunt -
Number of replies: 7
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The context for this is that when the OU tested Moodle 2.4, we found that it was too slow, so we have been looking for possible performance information. If you want a longer version of the story, see http://tjhunt.blogspot.co.uk/2013/05/performance-testing-moodle.html.

One thing that sam marshall noticed was that if your theme overrides several renderers, it is pretty inefficient. All the renderers get included in the renderers.php file of your theme, and that means that all those renderers have to be loaded on every page. And so all the base renderers like mod_quiz_renderer, and hence all the quiz code, gets loaded on every page, whether it is required or not.

So, in MDL-39590 I am suggesting an alternative. Instead of a single renderers.php file, we will instead have a renderers folder in the theme, containing files like

  • core_renderer.php
  • mod_choice_renderer.php
  • theme_mymobile_renderer.php

(to use the one in the mymobile theme as an example). The logic there is that the filename is the name of the base renderrer you are overriding.

In the OU theme, where we have 11 overridden renderers, that saves us 20ms, which may not sound like a lot, but that was a 2% speed-up in loading the particular page I was testing.

If your theme does not contain a renderers folder, but does contain a renderers.php file, then this change will not break it. We will go on loading the renderers.php.

The problem is themes like bootstrapbase and mymobile, where there is a renderers folder, but it does not contain files with the right names. I have fixed that, but it shows that this change was not 100% backwards compatible, as I had hoped it would be.

I think that switching from a single huge renderers.php file, to a set of separate renderers/component_name_renderer.php files, will also make things easier to work with.

Anyway, what I think is not important. You are the folks who will be affected by this, which is why I am posting here. What do you think of this proposed change?

Average of ratings: Useful (3)
In reply to Tim Hunt

Re: Making theme overridden renderers more efficient

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

+1 from me because I know how it works, from a previous discussion with you, and as a result have adopted it in themes I am currently working on. smile

It's strange you should post this question today, as I was only thinking earlier today that it's about time Bootstrapbase changed renderers/core.php to rendereres/core_renderer.php smile

Cheers

Mary

In reply to Mary Evans

Re: Making theme overridden renderers more efficient

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, if you could get that bootstrap change in before 2.5, that would be great, but we are probably too late.

In reply to Tim Hunt

Re: Making theme overridden renderers more efficient

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

+1 from me too. It makes sense to me to have the renderers for individual components (if they are being overriden in the theme) separate, particularly if this has the effect of speeding up page load times the way Tim describes.

In reply to Richard Oelmann

Re: Making theme overridden renderers more efficient

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

I've looked at the code and a +1 from me too.  Even if it breaks the API code for themes. I'm always coping with API changes in course formats (contributed / add-on), so this omelet needs its egg to be broken so it can be made.  As long as all core themes are changed, then contribs will just have to change too.

Cheers,

Gareth

In reply to Tim Hunt

Re: Making theme overridden renderers more efficient

by Danny Wahl -

I totally support this, the only issue might be that (I think...) there are some renderers that don't belong to a true "component" other than core that are simply named renderer.php - so how do we deal with those?  Maybe actually emulating the root file tree would be a little "better" for those scenarios...