From 9210bbf5fb91d850e6c2cceb9ca2dc3ceb5f4652 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 16 Aug 2023 11:21:30 +0000 Subject: [PATCH] [IMP] web: improve time taken to parse owl templates This commit removes some code that would allow one to define multiple templates with the same name, and would cause the the last template with a given name to override the previous one. This doesn't happen in practice, nor should it, and the code that is used to allow it repeatedly queries the document for a selector that is difficult to process (selecting for elements with a specific attribute value, especially when many elements in the document have that attribute). A simple profile, with the crm and project apps installed, brings the time that it takes to load the owl templates from ~200ms to ~35ms closes odoo/odoo#132044 Signed-off-by: Francois Georis (fge) --- addons/web/static/src/core/assets.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/addons/web/static/src/core/assets.js b/addons/web/static/src/core/assets.js index 27aff25c951..346489c61e4 100644 --- a/addons/web/static/src/core/assets.js +++ b/addons/web/static/src/core/assets.js @@ -113,21 +113,9 @@ export const _loadXML = (assets.loadXML = function loadXML(xml, app = defaultApp } for (const element of doc.querySelectorAll("templates > [t-name]")) { - const name = element.getAttribute("t-name"); - const previous = templates.querySelector(`[t-name="${name}"]`); - if (previous) { - console.debug("Override template: " + name); - previous.replaceWith(element); - } else { - templates.documentElement.appendChild(element); - } - } - if (app || defaultApp) { - console.debug("Add templates in Owl app."); - app.addTemplates(templates, app || defaultApp); - } else { - console.debug("Add templates on window Owl container."); + templates.documentElement.appendChild(element); } + app?.addTemplates(templates, app); }); /** * Update the default app to load templates.