From 0a8b7f6a5740f4b4f976eb308841ad3b98166015 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Thu, 28 Jul 2016 16:52:14 +0100 Subject: [PATCH] Perf comments: getFormatFromFile slows LyX startup considerably It is currently called on hundreds of files: settings, layouts, icons, cached graphics files (incl. graphics from files that are not opened on startup). According to callgrind, fixing the FIXME comments could speed up startup by more than 30%. --- src/ConverterCache.cpp | 4 ++++ src/Format.cpp | 4 ++++ src/Format.h | 1 + 3 files changed, 9 insertions(+) diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp index b87bfe56cc..7590336411 100644 --- a/src/ConverterCache.cpp +++ b/src/ConverterCache.cpp @@ -159,6 +159,10 @@ void ConverterCache::Impl::readIndex() FormatCache & format_cache = cache[orig_from_name]; if (format_cache.from_format.empty()) format_cache.from_format = + // FIXME perf: This very expensive function is called on all + // cached files on opening. This slows LyX startup a lot. It + // would be better if this information was retrieved in a + // delayed fashion. formats.getFormatFromFile(orig_from_name); format_cache.cache[to_format] = item; } diff --git a/src/Format.cpp b/src/Format.cpp index 503bfc58ab..c94481bb62 100644 --- a/src/Format.cpp +++ b/src/Format.cpp @@ -531,6 +531,10 @@ bool Formats::isZippedFile(support::FileName const & filename) const { map::iterator it = zipped_.find(fname); if (it != zipped_.end() && it->second.timestamp == timestamp) return it->second.zipped; + // FIXME perf: This very expensive function is called on startup on each + // file whic is going to be parsed, and also on svgz icons. Maybe there is a + // quicker way to check whether a file is zipped? I.e. for icons we + // probably just need to check the extension (svgz vs svg). string const & format = getFormatFromFile(filename); bool zipped = (format == "gzip" || format == "zip"); zipped_.insert(make_pair(fname, ZippedInfo(zipped, timestamp))); diff --git a/src/Format.h b/src/Format.h index 13bde5ff1f..74d2c4ea26 100644 --- a/src/Format.h +++ b/src/Format.h @@ -153,6 +153,7 @@ public: * fails, from file extension. * \returns file format if it could be found, otherwise an empty * string. + * This function is expensive. */ std::string getFormatFromFile(support::FileName const & filename) const; /// Finds a format from a file extension. Returns string() if not found. -- 2.39.5