[prev in list] [next in list] [prev in thread] [next in thread] 

List:       lyx-cvs
Subject:    [LyX/master] Perf comments: getFormatFromFile slows LyX startup considerably
From:       Guillaume Munch <gm () lyx ! org>
Date:       2016-07-31 17:36:26
Message-ID: 20160731173626.D0CBB280236 () lyx ! lyx ! org
[Download RAW message or body]

commit 0a8b7f6a5740f4b4f976eb308841ad3b98166015
Author: Guillaume Munch <gm@lyx.org>
Date:   Thu Jul 28 16:52:14 2016 +0100

    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(+), 0 deletions(-)

diff --git a/src/ConverterCache.cpp b/src/ConverterCache.cpp
index b87bfe5..7590336 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 503bfc5..c94481b 100644
--- a/src/Format.cpp
+++ b/src/Format.cpp
@@ -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)));
diff --git a/src/Format.h b/src/Format.h
index 13bde5f..74d2c4e 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.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic