get_list_of_timezones or how we waste several seconds on most pages

get_list_of_timezones or how we waste several seconds on most pages

Alexey Veretennikov發表於
Number of replies: 7
Hello, everyone!

I am a new Moodle user. Recently I've downloaded and installed the latest version (1.8.2) and found out that it works too slow on my server (Windows 2003, Apache 2.2, PHP 5.2, MySQL 5.0) even when no other resource-consuming tasks were running.

After a little investigastion I found a function get_list_of_timezones() in file admin\settings\location.php. It is called from this file twice and each time it takes about 1.7 seconds on my computer to complete it. So, 3.4 seconds (out of 9.1 which is needed to load the whole page with courses) for every user on most pages is just a waste of time. You can test it by editing the file admin\settings\location.php. Find the string
$options = get_list_of_timezones();
put before this string
$time_start = microtime(true);
and after this string
$time_end = microtime(true);
$time_total = $time_end - $time_start;
echo "Time total: $time_total seconds<br>";

The second call of this function is not needed at all and I've found that Samuli Karevaara already put this issue in the tracker (http://tracker.moodle.org/browse/MDL-8451). But somehow this issue is considered minor (though if we call this function once, not twice, we already have pages loading 15 % faster) and after 5 months there is no any progress.

Maybe someone more experienced can tell me if it is possible to do without this function at all? What for do we need all the timezones every time? If it is still a necessity maybe this function can be optimized much better than just removing its second call in location.php? I can look further into the get_string() function (which is called inside of get_list_of_timezones() many times in a cycle) because it seems that optimizing it we can get much more gain in performance for it is used in many other calls.

Thank you for your patience smile
評比平均分數: -
In reply to Alexey Veretennikov

Re: get_list_of_timezones or how we waste several seconds on most pages

Martín Langhoff發表於
Hadn't heard of this. Thanks for mentioning it.

Is this actually called on every pageload? Are you sure?
評比平均分數:Useful (1)
In reply to Martín Langhoff

Re: get_list_of_timezones or how we waste several seconds on most pages

Alexey Veretennikov發表於
I'm sorry to have said this happens on most pages. After checking out it seems that this file (location. php) is included when loading these pages:

1. The main page before logging in
2. The main page after logging in
If logged in as admin:
3. Notifications
4. All menu and submenu items in these menus: Users, Courses, Location, Language, Modules, Appearance, Front Page (except Front Page backup), Server, Networking, Reports, Miscellaneous.

So, most pages of administrative (not student's or teacher's) section are affected.

What is worse is that it takes up to 6.3 seconds for one call of get_list_of_timezones() when I change into Russian interface. This makes main page loading for 22.1 seconds in total.
In reply to Alexey Veretennikov

Re: get_list_of_timezones or how we waste several seconds on most pages

Martín Langhoff發表於
Hmmm. Reviewing the code...

The current Admin UI code wants to build an in-memory representation of all the admin keys, valudation rules, possible values etc, and we do this on every page to be able to display the admin menu (and in some cases, we _don't_ display it.

All we need is the top-level outline of it.

MartinD -- can this be decoupled?
評比平均分數:Useful (1)
In reply to Martín Langhoff

Re: get_list_of_timezones or how we waste several seconds on most pages

Dan Poltawski發表於
I think a way of decoupling this would make really great performance gains, one of the recent performance bugs was spotted with a related matter to this.

Displaying the admin menu requried filling in all the admin setting, one of which required a library file to declare a constant to set as its option - but the library file had other logic in it which got called.) A lot of work to be done to display a higher level menu link ;)
In reply to Dan Poltawski

Re: get_list_of_timezones or how we waste several seconds on most pages

Martín Langhoff發表於
Yes - Matt fixed one of those in the Calendar libraries recently.
In reply to Martín Langhoff

Re: get_list_of_timezones or how we waste several seconds on most pages

Martin Dougiamas發表於
Core developers的相片 Documentation writers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片
Wow, really? That's no good. Yes, those should be curtailed. We probably just need some global set at the top and then lots of these put in:

if ($ADMIN->calculatefulldata) {
// do the deep stuff
}

The blindingly obvious thing is get_list_of_timezones being called TWICE in location.php ... fixed that up right now (and added some caching in case we miss others) MDL-8451