Investigation and Profiling of Writer Load/Save Performance

We started a systematic profiling of the load/save performance on a current milestone (DEV300_m45). Im using Intel vTune on Windows and cachegrind (with cache-simulation) on Linux. On each platform each of the four documents (see Testdocuments below) is profiled for a load and a save procedure. Each measurement is done twice. In total, this will result in:

Identified Hotspots

Conversion of Hyperlinks

Conversion of hyperlinks takes a lot of time. To bring hyperlinks into the correct form and to make them relative to the target URL the methods from svt's URIHelper are used. This is done for _all_ URLs independent of the protocol. In the given document URLs are mostly http while the document is stored to file. One approach to solve this issue is to convert only if the protocols are the same. Another approach is to manage the hyperlinks within the document and to keep them in the correct form all the time. So they only have to be converted at the time the target URL changes (saveAs/storeToURL). On the given system this would save about 4 s from a total of 12 s save time. (stopwatch estimation)

Saving a file with a lot of fragment URLs "#bookmarkname" to a network share takes a lot of time. In comparision: DEV300 m41 takes about 1:55 min while os128 takes only 28s to save the document to a network share.

To make sure the file URLs are correctly normalized the dialog code to insert all kinds of links has to call the normalization. This applies to Insert/Hyperlink, Insert/Picture from File and others.

String Indexed Access of PropertySets

Another rather big part of processing time is consumed to access the members of the implementations of css::beans::XPropertySet, XPropertyState, XPropertySetInfo. To find the requested element by it's name the methods from SfxItemPropertySet, SfxItemPropertySetInfo etc. iterate over an array of structs that define a property (SfxItemPropertyMap). This can be seen by the numbers from SfxItemPropertyMap::getByName, rtl::OUString::equalsAsciiL, SfxItemPropertySetInfo::hasPropertyByName in the svl library.

The replacement for the SfxItemPropertyMap that uses an std::hash_map is ready. After changing a lot of code in the applications as well as in svtools, sfx2, svx and others I started to compare the load/save times.

The result is not as expected. In Media:Odfsave_withhash.ods you can see that SfxItemPropertyMap::getByName() takes longer than before. The new function takes about 5.3 s totally. These are about 1.7 s more than it's predecessor SfxItemPropertyMap::GetByName() required. The time is consumed mostly in the _M_Find<::rtl::OUString> method of the hash_map implementation.

One of the probable reasons is the fact that the sorted access to properties eliminated a lot of string comparisons.

Using XMultiPropertySet where XTolerantMultiPropertySet might suffice and be more performant

To decide which properties have to be saved xmloff uses the interface methods css::beans::XPropertyState::getPropertyStates() and css::beans::XMultiPropertySet::getPropertyValues(). It could also use the interface css::beans::XTolerantMultiPropertySet::getDirectPropertyValuesTolerant() which is not implemented for Writer's UNO objects.

Saving Writer's text content is done by iterating over the paragraphs and iterating over so-called text portions within the paragraphs. Text portions are parts of the paragraph that have a single attribute set, text fields, redline portions, inline anchored frames etc. It might make sense to detect their properties at construction time and preset their css::uno::XTolerantMultiPropertySet interface. And the moment a text portion is created that adds a bookmark to remember it's position. The impact on real documents is not yet checked.

A test implementation of the XTolerantMultiPropertySet in Writer's text portion objects didn't result in increased save speed.

Font Fallback

The huge contribution of GenerateAndStoreThumbnail in the callgrind measurements for some of the documents is attributed to substitution matching for missing fonts. This might be an issue to investigate.

Compressed files do not need to be compressed again in Storage

The large contribution of SfxMedium::Commit for documents "ScienceThesis" and "Manual" to StoreAsUrl in the callgrind analysis are attributed to the pictures in the document. We are investigating, if it might help to store image files that are already compressed (JPEG for examples) directly to the storage without trying to compress again in vain.

Iteration over Frame Collections

The methods SwDoc::GetFlyCount and SwDoc::GetFlyNum contribute more than 13 % of the instructions to SaveAsOwnFormat for the MailMerge document. The iteration over the frames array is O(n^2). Suggested solution: