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%.
This commit is contained in:
Guillaume Munch 2016-07-28 16:52:14 +01:00
parent 22d7ba6424
commit 0a8b7f6a57
3 changed files with 9 additions and 0 deletions

View File

@ -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;
}

View File

@ -531,6 +531,10 @@ bool Formats::isZippedFile(support::FileName const & filename) const {
map<string, ZippedInfo>::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)));

View File

@ -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.