Bug 156125 - Slow scrolling of documents with many Math formulas
Summary: Slow scrolling of documents with many Math formulas
Status: RESOLVED NOTOURBUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.0 all versions
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: perf
Depends on:
Blocks: Scrolling-PageUpDown
  Show dependency treegraph
 
Reported: 2023-07-02 18:17 UTC by Jan Rheinländer
Modified: 2024-04-15 06:18 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
Writer file containing numerous Math objects with varying font sizes (529.20 KB, application/vnd.oasis.opendocument.text)
2023-07-02 18:17 UTC, Jan Rheinländer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Rheinländer 2023-07-02 18:17:34 UTC
Created attachment 188162 [details]
Writer file containing numerous Math objects with varying font sizes

When editing a Writer document that has many Math formulas, scrolling can become irregular.
After examining this with callgrind, I found the reason in vcl/unx/generic/fontmanager/fontconfig.cxx class CachedFontConfigFontOptions. Here the font options cache is coded to a size of 10.

Apparently Math formulas can contain a lot of fonts in varying sizes. Thus the font cache is quickly filled. On scrolling, an enormous amount of calls to PrintFontManager::getFontOptions() is generated. Unless cached, these are handled by libfontconfig's  FcFontSetMatch(). On typical Ubuntu systems, several thousand fonts can be installed (run fc-list). Thus libfontconfig uses a significant time to handle the calls.

Scrolling performance can be greatly improved by increasing the font options cache size to e.g. 100. Since memory usage is probably not as critical as it used to be when the font options cache was first implemented, that should be a safe change.

Find attached a sample file with a lot of Math formulas containing different font sizes.
Comment 1 IvoErMejo 2023-07-03 08:52:31 UTC
Bug unconfirmed: scroll for me is fluid
tested inside
Version: 7.5.5.1 (X86_64) / LibreOffice Community
Build ID: 2c5e46c1980ec5241359fd65d751dc518205e7af
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: it-IT (it_IT); UI: it-IT
Calc: threaded
Comment 2 Rafael Lima 2023-07-03 14:05:14 UTC
(In reply to Jan Rheinländer from comment #0)
> Created attachment 188162 [details]
> Writer file containing numerous Math objects with varying font sizes

Scrolling with the sample document is very fluid with:

Version: 7.5.4.2 (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 16; OS: Linux 6.2; UI render: default; VCL: kf5 (cairo+xcb)
Locale: pt-BR (pt_BR.UTF-8); UI: pt-BR
Ubuntu package version: 4:7.5.4-0ubuntu0.23.04.1
Calc: threaded

I'm on Kubuntu 23.04 under X11.

Can you provide more details about your system? Are you on Wayland?
Comment 3 Rafael Lima 2023-07-03 14:11:59 UTC
Scrolling seems to be affected in Wayland when using the mouse scroll (not with PgUp/PgDown).

I opened the sample document on a Wayland session (Kubuntu 23.04 / Intel graphics) and scrolling is sluggish with the mouse wheel. Scrolling using the PgUp and PgDown keys works as expected.
Comment 4 Jan Rheinländer 2023-07-03 18:37:28 UTC
On my system, all scrolling is sluggish (tried Pg Up / Pg Dn, pulling the scroll bar with the mouse). And the sluggishness disappears when I set the cache from 10 to 100, except for a small delay in the beginning while the cache is being populated (this was tested on my own build of 7.5.3.2.0)

I think the number of installed fonts might be relevant. fc-list | wc -l gives me 2415 fonts.

Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.3
Calc: threaded

/etc/lsb-release: Ubuntu 22.04.2 LTS

How do I check for Wayland?
Comment 5 Jan Rheinländer 2023-07-03 18:42:53 UTC
Please note that I reported the bug for Linux only. Windows is not affected because it does not use libfontconfig.
Comment 6 Stéphane Guillou (stragu) 2023-07-04 12:31:28 UTC Comment hidden (off-topic)
Comment 7 Stéphane Guillou (stragu) 2023-07-04 12:34:23 UTC
And for GTK3: bug 154602.
Comment 8 Stéphane Guillou (stragu) 2023-07-04 13:07:53 UTC Comment hidden (off-topic)
Comment 9 Jan Rheinländer 2023-07-04 17:28:12 UTC
Seems I am not using wayland:
echo $XDG_SESSION_TYPE results in "x11"

The way suggested by Stéphane didn't work, maybe because I am using German KUbuntu.
Comment 10 Jan Rheinländer 2023-07-04 17:54:38 UTC
Unfortunately 7.0 and 7.1 and 7.3 show no difference for me.

Apart from the sluggish scrolling, all three will push CPU usage of soffice.bin to 50-90% when dragging the scrollbar with the mouse up and down repeatedly.

Interestingly, Xorg CPU usage is < 5% on 7.0 and 7.1 but 10-15% on 7.3
Comment 11 Stéphane Guillou (stragu) 2023-07-05 13:26:24 UTC
Thanks for checking.
I've opened bug 156169 for my findings. Marking my comments here as off-topic.
Comment 12 Roman Kuznetsov 2023-07-08 11:37:36 UTC
(In reply to Jan Rheinländer from comment #10)
> Unfortunately 7.0 and 7.1 and 7.3 show no difference for me.
> 
> Apart from the sluggish scrolling, all three will push CPU usage of
> soffice.bin to 50-90% when dragging the scrollbar with the mouse up and down
> repeatedly.
> 
> Interestingly, Xorg CPU usage is < 5% on 7.0 and 7.1 but 10-15% on 7.3

What about to try more modern LibreOffice version like 7.4 or 7.5?
Comment 13 Jan Rheinländer 2023-07-08 19:27:35 UTC
No noticeable improvement with:

Version: 7.5.4.2 (X86_64) / LibreOffice Community
Build ID: 36ccfdc35048b057fd9854c757a8b67ec53977b6
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: en-US
Calc: threaded

and

Version: 7.5.5.1 (X86_64) / LibreOffice Community
Build ID: 2c5e46c1980ec5241359fd65d751dc518205e7af
CPU threads: 4; OS: Linux 5.15; UI render: default; VCL: kf5 (cairo+xcb)
Locale: de-DE (de_DE.UTF-8); UI: en-US
Calc: threaded
Comment 14 Buovjaga 2023-09-04 16:02:51 UTC
Not reproduced here with 877 fonts.

Tempted to set to NEW per comment 3, but on the other hand Rafael could not repro under X11, so we can't be sure it's the same thing...

Arch Linux 64-bit, X11
Version: 7.6.0.3 (X86_64) / LibreOffice Community
Build ID: 60(Build:3)
CPU threads: 8; OS: Linux 6.4; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
7.6.0-2
Calc: threaded
Comment 15 Stéphane Guillou (stragu) 2023-09-05 09:23:20 UTC
One thing we haven't checked is if Jan tried it with a new profile.
Jan, can you please test in safe mode with Help > Restart in Safe Mode > Restart > Continue in Safe Mode?
If it fixes the issue, you can reset your user profile (keeping in mind will lose settings, personal info and document history) with "Reset to factory settings" in the same dialog.
Or rename your user profile directory to keep the older version and restore it if needed. https://wiki.documentfoundation.org/UserProfile#Manual_procedure_(all_versions)
Comment 16 Jan Rheinländer 2023-09-05 16:38:18 UTC
I tested in Safe Mode but could not notice a difference. What did make a difference was reducing the number of installed fonts on my system from >2400 to about 470. 

I don't think anybody has ever tried to confirm this bug with more than 800 fonts installed?
Comment 17 Eyal Rozenberg 2023-09-05 17:10:53 UTC
What kind of "irregular" scrolling should I expect? Scrolling for me in LO is never perfectly "fluid" even with plain text and the default font. Perhaps with this document it takes more processing to scroll, and on a slower machine there is lag? Please explain this better.

Otherwise can't really reproduce on:

Version: 7.6.0.3 (X86_64) / LibreOffice Community
Build ID: 69edd8b8ebc41d00b4de3915dc82f8f0fc3b6265
CPU threads: 4; OS: Linux 6.4; UI render: default; VCL: gtk3
Locale: en-IL (en_IL); UI: en-US

... and I have 6914 fonts according to fc-list.
Comment 18 Jan Rheinländer 2023-09-10 04:44:06 UTC
Since nobody else seems to experience this problem, I would like to close the bug. Probably it is just my old machine coping badly with complex documents.
Comment 19 Armondo Lopez 2024-04-14 21:01:17 UTC
I didn't experience any abnormal scroll lag in

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: a2265e8faa099d9652efd12392c2877c2df1d1eb
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: default; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded

or

Version: 24.2.1.2 (X86_64) / LibreOffice Community
Build ID: db4def46b0453cc22e2d0305797cf981b68ef5ac
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: default; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: threaded
Comment 20 Telesto 2024-04-15 06:18:43 UTC
(In reply to Jan Rheinländer from comment #18)
> Since nobody else seems to experience this problem, I would like to close
> the bug. Probably it is just my old machine coping badly with complex
> documents.

Marking it as RESOLVED -> NOTOURBUG