ODT saving performance improvement

From Apache OpenOffice Wiki
Jump to: navigation, search


1. Investigation of ODT saving performance

We started a profiling of the saving performance on a current AOO build with Quantify on Windows. One document(sw_complex_100p.odt) are profiled for a save procedure.

The analysis of the data should be:

  • show, if the profiler output is stable and reproducible
  • identify the hotspots of the current implementation
  • be a basis to evaluate the progress by optimization

For benchmark document: sw_complex_100p.odt, it is consisted of many graphics. Following shows the hotspots(marked in blue) in saving procedure.

Odt_saving.jpg

From these data, we can know, SfxObjectShell::GenerateAndStoreThumbnail and SwGrfNode::SwapIn occupy too much time than expected.

For SfxObjectShell::GenerateAndStoreThumbnail, we found it will call SwFlyFrm::Paint several times, but it's unnecessary to paint thumbnail so many times when saving.

For SwGrfNode::SwapIn, through analyzing data collected from quantify, one phenomenon is that graphic will be first swapped in, after saving, it will be swapped out. If document contains lots of graphics, it will influence saving performance immensely.

2. Solution

  • Don't paint thumbnail so many times in saving procedure.

When thumbnail is generated and stored, in SwFlyFrm::Paint, current visible rectangle will be compared with fly frame rectangle, if the two rectangles don't intersect, SwFlyFrm::Paint will return.

  • Don't swap out and swap in graphics so frequently when saving.

3. Graphic Management Mechanism

Give a brief description to solution 2.

3.1. Graphic Manager

Graphic Manager is responsible for all graphic objects’ register, unregister, drawing, and graphic’s cache. It is a global variable.

3.2. Graphic Cache

For management of Graphic Cache, Graphic Manager supplies a series of interfaces: graphic object cache size settings, swap graphic in, swap graphic out, swap timer, etc.

  • Contents of graphic cache

Graphic cache includes two parts: one is the image that presents to user, namely graphic’s bitmap or metafile A; the other is when graphic is registered or unregistered, the image that dynamically existing, it is the graphic before it transforming to bitmap or metafile, namely B.

  • Settings of graphic cache

Image that presents to user, namely graphic’s bitmap or metafile A, its size can be set through interface. Below is conventional diagram.

Cache.jpg

  • Swap in/out of temp file

Graphic that before it transforming to bitmap or metafile, namely B. For its memory management, there is only one copy in memory, no matter how many times it is be used. In addition, it will be swapped in memory as temp file only when the graphic is present to user, that is to say, you can see it with your eyes. When move to next page, it will be swapped out to disk again.

3.3. Optimization of graphic cache

Sample file: document that contains lots of graphic (bmp, jpg, wmf) in it.

Root cause: Graphic will be swapped in memory as temp file only when the graphic is present to user, that is to say, you can see it with your eyes. When move to next page, it will be swapped out to disk again.

Solution: Do limit on memory B’s size. In order to avoid frequently swapping in/out, do limit on B like A, a max memory M will set to B. If exceeding M, the swap out and vice versa.

Personal tools