-
Improvement
-
Resolution: Fixed
-
Minor
-
4.5
-
MOODLE_405_STABLE
-
MOODLE_500_STABLE
-
MDL-82754-main -
-
-
6
-
Team Hedgehog 2024 Sprint 3.2, Team Hedgehog 2024 Sprint 3.3, Team Hedgehog 2024 Review 4, Team Hedgehog 2024 Sprint 4.1, Team Hedgehog 2024 Sprint 4.2, Team Hedgehog 2024 Sprint 4.3
On the home page, whether on the dashboard, home, myhome or whatever is configured in your Moodle that lists all of a teacher's courses. If the number of these courses is very large and teachers prefer the list as "all", there is a major performance problem in the "treatStringsInContent()" method, which replaces placeholders in a string with their respective translations, that is, replacing placeholders found in a string.
Previously, they used String.replace() to replace placeholders, but the complexity increased with the number of strings to be replaced. Now, they manually go through the string and replace placeholders as they find them.
However, currently there is this major problem of multiple string concatenations, which are costly in performance.
Therefore, I am proposing a solution using a String Builder through an array, which will reduce the amount of concatenation within the while loop, causing a significant increase in performance.
In a local test with more than 200 courses listed, the performance difference was more than 50 seconds.
Step by step to simulate the problem:
- Log in to your Moodle with a teacher who has the maximum number of courses possible, preferably more than 100 courses that can be listed, and a page that lists all the courses of this teacher. After loading, if there is pagination, choose the "all" option as default, to list all the courses.
- In dev tools, go to performance -> start recording -> refresh the page that lists the courses, and after loading all the courses with their images, stop recording. Then, analyze the performance in:
- Call Tree -> timer triggered -> execute microtasks -> ProcessRenderedContent -> treatStringsInContent through this, it is possible to note the execution time of the treatStringsInContent method.* Step by step to simulate the solution:
Afterwards, it is possible to change the code in this method and implement the proposed improvement, applying a String Builder with an array in the treatStringsInContent method. After that, replicate the testing process mentioned above and see that the time is much shorter and performance is better.- FILE: renderer.js - METHOD: treatStringsInContent()
- PATH: /moodle/lib/amd/src/local/templates/renderer.js
- New code with modification: Attached in this improvement in: solution.js
Note: The attached file only contains the code of the method to be improved, not the entire renderer.js file.
Att, Jean Marcos Sotoriva.
Rio Grande do Sul, Brasil.