Bug 492529 - okular is very slow opening some PDFs
Summary: okular is very slow opening some PDFs
Status: RESOLVED NOT A BUG
Alias: None
Product: okular
Classification: Applications
Component: PDF backend (show other bugs)
Version: 24.08.0
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-02 07:13 UTC by William Bader
Modified: 2024-09-08 12:42 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William Bader 2024-09-02 07:13:25 UTC
SUMMARY
I have a single page PDF that takes okular over a minute to open, while gv/gs opens it almost instantly and atril and evince open it in a few seconds.

STEPS TO REPRODUCE
1. view the file with okular

OBSERVED RESULT
It takes over a minute to paint completely (Fedora 40 Linux on an i7-12800H laptop)

EXPECTED RESULT
It should take a few seconds like atril and evince, since I think that all three use the same libpoppler.

SOFTWARE/OS VERSIONS
Linux: Fedora 40
Desktop: mate 1.28

ADDITIONAL INFORMATION
Comment 2 William Bader 2024-09-02 07:44:33 UTC
Hopefully viewing the PDF with a profiling build of okular will identify the problem. I think that okular, atril, and evince all use libpoppler as the back-end for PDFs, and usually okular is faster, I think because atril and evince do an extra layer of copying internally.
My laptop is using xorg-x11-server-Xorg-1.20.14 and xorg-x11-drv-nvidia-560.35.03 with an NVIDIA GeForce RTX 3050 Laptop GPU.
Fedora 40 has poppler-24.02.0
Maybe the PDF has a large image with a color format that doesn't match any of the formats provided by X.
pdftops -level1sep takes 54 seconds, while pdftops -level2 takes under 1 second, so maybe okular is interfacing with poppler in a way that poppler think that it needs to use splash.
Comment 3 Justin Zobel 2024-09-02 08:03:30 UTC
I've just opened this PDF in Okular on two different devices, and it loads within 1–2 seconds. Are you able to boot a live ISO of another OS and test the file there? It might be some tuning thing on Fedora that is causing the issue.
Comment 4 Timothée Ravier 2024-09-02 09:11:49 UTC
I've opened this PDF in fresh Fedora 40 and Fedora 41 VMs and it loaded in 1-2 seconds. It also loads quickly on my Kinoite 40 installation with Flathub's Okular so I recommend giving this a try to narrow down the potential root cause: https://flathub.org/apps/org.kde.okular
Comment 5 William Bader 2024-09-02 16:52:18 UTC
(In reply to Timothée Ravier from comment #4)
> I've opened this PDF in fresh Fedora 40 and Fedora 41 VMs and it loaded in
> 1-2 seconds. It also loads quickly on my Kinoite 40 installation with
> Flathub's Okular so I recommend giving this a try to narrow down the
> potential root cause: https://flathub.org/apps/org.kde.okular

Thank you for the reply. I'm willing to try that. Fedora provides flatpak. It looks like it would install about a GB.
After testing, can I used `flatpack uninstall ...` to remove everything that `flatpak install flathub org.kde.okular` loaded?

My laptop has no CD drive, but it has USB 3 and 64 GB RAM, so I can boot ISOs copied to usb sticks (which is how I tested Fedora 40 before updating to it), but I would rather test with flatpak or a VM first.

```$ flatpak install flathub org.kde.okular
Looking for matches…
Required runtime for org.kde.okular/x86_64/stable (runtime/org.kde.Platform/x86_64/6.7) found in remote flathub
Do you want to install it? [Y/n]: y

org.kde.okular permissions:
    ipc                  network      cups      fallback-x11      pulseaudio      wayland      x11      dri      file access [1]
    dbus access [2]

    [1] host, xdg-config/kdeglobals:ro
    [2] com.canonical.AppMenu.Registrar, org.kde.KGlobalSettings, org.kde.kconfig.notify


        ID                                                        Branch                  Op             Remote              Download
 1.     org.freedesktop.Platform.GL.default                       23.08                   i              flathub             < 170.7 MB
 2.     org.freedesktop.Platform.GL.default                       23.08-extra             i              flathub             < 170.7 MB
 3.     org.freedesktop.Platform.GL.nvidia-560-35-03              1.4                     i              flathub             < 323.4 MB
 4.     org.freedesktop.Platform.VAAPI.Intel                      23.08                   i              flathub              < 13.4 MB
 5.     org.freedesktop.Platform.openh264                         2.2.0                   i              flathub             < 944.3 kB
 6.     org.kde.KStyle.Adwaita                                    6.7                     i              flathub               < 8.1 MB
 7.     org.kde.Platform.Locale                                   6.7                     i              flathub             < 393.3 MB (partial)
 8.     org.kde.Platform                                          6.7                     i              flathub             < 333.9 MB
 9.     org.kde.okular.Locale                                     stable                  i              flathub               < 2.8 MB (partial)
10.     org.kde.okular                                            stable                  i              flathub              < 35.5 MB

Proceed with these changes to the system installation? [Y/n]: n
```
Comment 6 William Bader 2024-09-02 17:06:48 UTC
(In reply to Justin Zobel from comment #3)
> I've just opened this PDF in Okular on two different devices, and it loads
> within 1–2 seconds. Are you able to boot a live ISO of another OS and test
> the file there? It might be some tuning thing on Fedora that is causing the
> issue.

Thank you for the reply.
Is it possible that I set something wrong in okular?
I have the default settings, except since my laptop has a cpu with 20 threads and has 64 GB RAM, in Okular -> Configure -> Performance, I set Memory Usage to "Greedy".
I also currently have
CPU usage: [ ] Enable transparency effects (not set)
Rendering options:
  [x] Enable text antialias (set)
  [ ] Enable graphic antialias (not set)
  [ ] Enable text hinting (not set)

I use okular to read long documents. I want the text clear, but I don't care if the images aren't as clear as possible.

My Linux installation runs X with Mate Desktop (Wayland isn't an option with Mate), and I think that I have X configured to use the built-in Intel GPU primarily while making the nvidia GPU available to applications.
My laptop has a 4K (3840x2160) display, and I use mate-tweaks to configure for hidpi. 

I think that my hardware and OS configuration are ok because evince and atril open the test page in a few seconds, maybe about 30X faster than okular, but I am open to suggestions.

Regards, William
Comment 7 Justin Zobel 2024-09-03 00:58:51 UTC
Yes, you can remove Okular using the command you listed once you no longer need it. It may leave some runtimes as they can be reused later, or if you want you can remove those as well with `flatpak uninstall --unused`. And you can remove leftover user data/cache data in ~/.var/app/org.kde.okular as well if you want to truly clean up.

I'd suggest testing with the Flatpak Okular as it won't have any changed settings and seeing if there is a difference in load times.
Comment 8 William Bader 2024-09-03 06:45:59 UTC
(In reply to Justin Zobel from comment #7)
> I'd suggest testing with the Flatpak Okular as it won't have any changed
> settings and seeing if there is a difference in load times.

Thanks!!!
Testing with the flatpak version was a good idea.
The flatpak version was almost instant for me.
I compared the settings under Settings -> Configure Okular -> Performance
The flatpak had "enable graphics antialias" checked.
My local okular had it unchecked. (I had done that a long time ago because I thought that antialiasing made it slower.)
I checked it, and it went from a minute to almost instant rending the sample PDF.

I had thought that antialias rendered at a higher resolution and then averaged the high resolution image down to the displayed resolution, so enabling antialias is usually a few times slower.
I didn't expect that enabling antialias in okular would be about 50 times faster instead of a few times slower.
If antialias is off, does okular revert to a slower method (like using poppler splash)?

I tried unsetting antialias for both text and graphics to see if having them set differently was the problem, but having them both unchecked was still slow.

Anyway, thanks, enabling graphics antialias solved the problem!

Thanks again!
William
Comment 9 Justin Zobel 2024-09-05 06:52:02 UTC
I'm not sure why it makes such a large performance difference, just glad it we figured out the case. Hopefully someone with more knowledge can answer the why!.
Comment 10 Albert Astals Cid 2024-09-08 12:42:01 UTC
> does okular revert to a slower method (like using poppler splash)?

Just for reference, Okular always uses Splash