From 06369a5351ac9b0fc146e225658bd088f06c4484 Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Wed, 3 Apr 2024 22:06:07 +0200 Subject: [PATCH] Startup screen template list: Avoid loading icons twice Rendering the SVG icons of templates is a huge bottleneck in the startup time. (ca. 1-2 seconds). Cut this startup time in half by rendering each file only once and then caching the result. This saves ca. 0.5-1 second of startup time because currently we have ca. 90 templates but only 37 distinct icons. --- src/ui/widget/template-list.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/ui/widget/template-list.cpp b/src/ui/widget/template-list.cpp index f516e85750..240fe86158 100644 --- a/src/ui/widget/template-list.cpp +++ b/src/ui/widget/template-list.cpp @@ -108,13 +108,20 @@ void TemplateList::init(Inkscape::Extension::TemplateShow mode) */ Glib::RefPtr TemplateList::icon_to_pixbuf(std::string const &path) { - // TODO: Add some caching here. - if (!path.empty()) { - Inkscape::svg_renderer renderer(path.c_str()); - return renderer.render(1.0); + // TODO: cache to filesystem. This function is a major bottleneck for startup time (ca. 1 second)! + // The current memory-based caching only catches the case where multiple templates share the same icon. + static std::map> cache; + if (path.empty()) { + Glib::RefPtr no_image; + return no_image; } - Glib::RefPtr no_image; - return no_image; + if (cache.contains(path)) { + return cache[path]; + } + Inkscape::svg_renderer renderer(path.c_str()); + auto result = renderer.render(1.0); + cache[path] = result; + return result; } /** -- GitLab