Saturday, December 11, 2021
2 changes · master
Miscellaneous changes
Avoid iterating over all channels every time a new channel is added. Part of task-2702450 Forward-Port-Of: odoo/odoo#81251 Forward-Port-Of: odoo/odoo#80698
Original PR description
Avoid iterating over all channels every time a new channel is added. Part of task-2702450 Forward-Port-Of: odoo/odoo#81251 Forward-Port-Of: odoo/odoo#80698
Currently each call to account_reports.render() loops through each js_account_report_foldable lines and calls this.fold on it. In turn, this.fold searches this.$el to retrieve the 'tr' objects to hide in the report. This means that currently the rendering process is more or less in O(n²) with n the number of lines in the report. To improve that, call this.$el.getElementsByTagName('tr') only once and then apply the 'fold' modifications to the correct lines. This greatly reduces the time
Original PR description
Currently each call to account_reports.render() loops through each js_account_report_foldable lines and calls this.fold on it. In turn, this.fold searches this.$el to retrieve the 'tr' objects to…
Currently each call to account_reports.render() loops through
each js_account_report_foldable lines and calls this.fold on it.
In turn, this.fold searches this.$el to retrieve the 'tr' objects
to hide in the report. This means that currently the rendering
process is more or less in O(n²) with n the number of lines in the report.
To improve that, call this.$el.getElementsByTagName('tr') only once
and then apply the 'fold' modifications to the correct lines.
This greatly reduces the time taken by the browser to render
a given account_reports when the number of lines gets bigger (>2000).
#### speedup
Time taken by the render function of `account_report.js` w.r.t. the number of foldable lines in the report.
The times reported were measured using the 'Aged Receivable' report but should be applicable to every report inheriting account.report.
Time reported for Chrome / Firefox
| Lines | Before PR | After PR |
|:-----:|:-----------:|:--------:|
| 100 | 19ms / 35ms | 6ms / 15ms |
| 500 | 232ms / 359ms | 37ms / 61ms |
| 2000 | 3.8s / 5.3s | 127ms / 190ms |
| 5000 | 23s / 32s | 210ms / 330ms |
| 10000 | 1min30s / 2min | 366ms / 632ms|
Forward-Port-Of: odoo/enterprise#22755
Forward-Port-Of: odoo/enterprise#19992