Page MenuHome GnuPG

Kleopatra: Improve startup performance
Closed, ResolvedPublic

Description

This is intended to be a meta issue to improve the use case:

  1. All background processes and Kleopatra closed
  2. Right click a file and select sign + encrypt.

-> The time it takes until the Windows is shown and functional and the sign/encrypt button is clickable.

On a fairly fast VM this takes an average of about 5 Seconds. It can sometimes take much longer, I think auto-check-trustdb could be a reason for this.
Startup timing shows the SelfCheck completed after about 1s.

Event Timeline

aheinecke lowered the priority of this task from High to Normal.Oct 27 2022, 10:41 AM

Another thing I have noticed when turning qt debug output on is that the qt windows platformsupport fontdatabase logs over a a timespan of over two seconds that it is adding fonts to its database.

void QWindowsFontDatabase::populateFontDatabase()
{
    removeApplicationFonts();
    HDC dummy = GetDC(0);
    LOGFONT lf;
    lf.lfCharSet = DEFAULT_CHARSET;
    lf.lfFaceName[0] = 0;
    lf.lfPitchAndFamily = 0;
    EnumFontFamiliesEx(dummy, &lf, populateFontFamilies, 0, 0);
    ReleaseDC(0, dummy);
    // Work around EnumFontFamiliesEx() not listing the system font.
    QString systemDefaultFamily = QWindowsFontDatabase::systemDefaultFont().family();
    if (QPlatformFontDatabase::resolveFontFamilyAlias(systemDefaultFamily) == systemDefaultFamily)
        QPlatformFontDatabase::registerFontFamily(systemDefaultFamily);
    addDefaultEUDCFont();
}

The only place where they can be changed afaik is to change the fonts of certificate list in kleopatra settings. I think we can drastically reduce that list or just remove that option and patch qt to only load the system font.

aheinecke moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.Jan 18 2023, 10:17 AM

I am somehwat confused, my symantec system got faster. But there are some things like "Symantec Insight" which will whitelist often used files and applications, also signed files might get preferred treatment. I tried to get this slower by disabling the "Insight" and changing the "Bloodhound behavior" to agressive... So timings might not be comparable. I should probably do tests ohne without restarting my systems for a good comparison.

Anyway. Here is my baseline, nearly unmodified, with some bits of code moved around and added timings:

[1956] org.kde.pim.kleopatra: ReaderStatus::Private: Using deprecated FileSystemWatcher
[1956] org.kde.pim.libkleo: adding
[1956]   "C:\\Users\\g10code\\AppData\\Roaming\\gnupg" 
[1956] /end
[1956] org.kde.pim.kleopatra: Startup timing: 343 ms: Application created
[1956] org.kde.pim.kleopatra: Responder handle: 0x0
[1956] org.kde.pim.kleopatra: Created responder:  0x8fc5c4  with handle:  0x4035c
[1956] org.kde.pim.kleopatra: Startup timing: 345 ms: Service created
[1956] Attribute Qt::AA_EnableHighDpiScaling must be set before QCoreApplication is created.
[1956] org.kde.pim.kleopatra: Application created
[1956] org.kde.pim.kleopatra: Startup timing: 346 ms: GPGME Initialized
[1956] org.kde.pim.libkleo: No signed VERSION file found.
[1956] org.kde.pim.libkleo: Parsed 2.2.41 as:  2 . 2 . 41 .
[1956] org.kde.pim.libkleo: Running gpgconf --show-versions ...
[1956] org.kde.pim.libkleo: gpgconf stdout: ""
[1956] org.kde.pim.kleopatra: Startup timing: 1036 ms: Versions checked
[1956] org.kde.pim.kleopatra: Got ElevationToken  0
[1956] org.kde.pim.kleopatra: Startup timing: 1036 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 305
[1956] org.kde.pim.kleopatra: Startup timing: 1044 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 314
[1956] org.kde.pim.kleopatra: Startup timing: 1148 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 316
[1956] org.kde.pim.kleopatra: Startup timing: 1149 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 324
[1956] org.kde.pim.libkleo: agentIsRunning : Connecting to the agent failed.
[1956] org.kde.pim.libkleo: Starting gpgconf (QProcess(0x200ebd0)) with arguments "--launch gpg-agent" ...
[1956] org.kde.pim.libkleo: gpgconf (QProcess(0x200ebd0)) was started successfully
[1956] org.kde.pim.kleopatra: Startup timing: 3209 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 326
[1956] org.kde.pim.kleopatra: Startup timing: 3209 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 329
[1956] org.kde.pim.libkleo: adding
[1956]   "C:/Users/g10code/AppData/Roaming/gnupg\n C:/Users/g10code/AppData/Roaming/gnupg/private-keys-v1.d\n C:/Users/g10code/AppData/Roaming/gnupg/pubring.kbx\n C:/Users/g10code/AppData/Roaming/gnupg/trustdb.gpg" 
[1956] /end
[1956] org.kde.pim.kleopatra: Startup timing: 3212 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 331
[1956] org.kde.pim.kleopatra: Startup timing: 3253 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 333
[1956] org.kde.pim.kleopatra: Startup timing: 3254 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 335
[1956] org.kde.pim.kleopatra: Startup timing: 3254 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 337
[1956] org.kde.pim.kleopatra: Startup timing: 3254 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 346
[1956] kf.windowsystem: Could not find any platform plugin
[1956] org.kde.pim.kleopatra: Startup timing: 3259 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp init 351
[1956] org.kde.pim.kleopatra: Startup timing: 3259 ms: Application initialized
[1956] org.kde.pim.kleopatra: Startup timing: 3260 ms: UiServer created
[1956] org.kde.pim.kleopatra: Startup timing: 3268 ms: UiServer started
[1956] org.kde.pim.kleopatra: Checking Windows Registry...
[1956] org.kde.pim.kleopatra: Checking Ui Server connectivity...
[1956] org.kde.pim.kleopatra: UiServer: client connect on fd  1280
[1956] org.kde.pim.kleopatra: UiServer: client connection  0x45e4658  established successfully
[1956] org.kde.pim.libkleopatraclientcore: Server PID = 1956
[1956] org.kde.pim.kleopatra: UiServer: connection  0x45e4658  closed
[1956] org.kde.pim.kleopatra: Checking gpg installation...
[1956] org.kde.pim.kleopatra: Checking gpgsm installation...
[1956] org.kde.pim.kleopatra: Checking gpgconf installation...
[1956] org.kde.pim.kleopatra: Checking configuration of: 
[1956] org.kde.pim.kleopatra: Checking configuration of: gpg
[1956] org.kde.pim.kleopatra: Checking configuration of: gpg-agent
[1956] org.kde.pim.kleopatra: Checking configuration of: scdaemon
[1956] org.kde.pim.kleopatra: Checking configuration of: gpgsm
[1956] org.kde.pim.kleopatra: Checking configuration of: dirmngr
[1956] org.kde.pim.libkleo: KeyFilterManager:: reload final filter count is 17
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] ("C:\\Gpg4win\\..\\GnuPG/bin/gpgtar", "--utf8-strings", "--openpgp", "--skip-crypto", "--output", "-", "--encrypt", "-T-", "--null", "--")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] find -print0 |  "C:/Gpg4win/../GnuPG/bin/gpgtar.exe" ("--utf8-strings", "--openpgp", "--skip-crypto", "--output", "-", "--encrypt", "-T-", "--null", "--")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] ("C:\\Gpg4win\\..\\GnuPG/bin/gpgtar", "--utf8-strings", "--cms", "--skip-crypto", "--output", "-", "--encrypt", "-T-", "--null", "--")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] find -print0 |  "C:/Gpg4win/../GnuPG/bin/gpgtar.exe" ("--utf8-strings", "--cms", "--skip-crypto", "--output", "-", "--encrypt", "-T-", "--null", "--")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] ("C:\\Gpg4win\\..\\GnuPG/bin/gpgtar", "--utf8-strings", "--openpgp", "--skip-crypto", "--set-filename", "%F", "--decrypt", "--", "-")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] "C:/Gpg4win/../GnuPG/bin/gpgtar.exe" ("--utf8-strings", "--openpgp", "--skip-crypto", "--set-filename", "%F", "--decrypt", "--", "-") "%f" ()
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] ("C:\\Gpg4win\\..\\GnuPG/bin/gpgtar", "--utf8-strings", "--cms", "--skip-crypto", "--set-filename", "%F", "--decrypt", "--", "-")
[1956] org.kde.pim.kleopatra: ArchiveDefinition[ "tar" ] "C:/Gpg4win/../GnuPG/bin/gpgtar.exe" ("--utf8-strings", "--cms", "--skip-crypto", "--set-filename", "%F", "--decrypt", "--", "-") "%f" ()
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha256sum" ] ("C:\\Gpg4win/bin/sha256sum", "-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha256sum" ] find -print0 |  "C:/Gpg4win/bin/sha256sum.exe" ("-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha256sum" ] ("C:\\Gpg4win/bin/sha256sum", "-c")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha256sum" ] "C:/Gpg4win/bin/sha256sum.exe" ("-c") "%f" ()
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha1sum" ] ("C:\\Gpg4win/bin/sha1sum", "-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha1sum" ] find -print0 |  "C:/Gpg4win/bin/sha1sum.exe" ("-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha1sum" ] ("C:\\Gpg4win/bin/sha1sum", "-c")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "sha1sum" ] "C:/Gpg4win/bin/sha1sum.exe" ("-c") "%f" ()
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "md5sum" ] ("C:\\Gpg4win/bin/md5sum", "-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "md5sum" ] find -print0 |  "C:/Gpg4win/bin/md5sum.exe" ("-0", "-")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "md5sum" ] ("C:\\Gpg4win/bin/md5sum", "-c")
[1956] org.kde.pim.libkleo: ChecksumDefinition[ "md5sum" ] "C:/Gpg4win/bin/md5sum.exe" ("-c") "%f" ()
[1956] org.kde.pim.kleopatra: 
[1956] org.kde.pim.kleopatra: 
[1956] org.kde.pim.kleopatra: Startup timing: 4364 ms: SelfCheck completed
[1956] org.kde.pim.kleopatra: openOrRaiseMainWindow
[1956] org.kde.pim.kleopatra: Startup timing: 4364 ms: Creating MainWindow
[1956] org.kde.pim.kleopatra: Waiting for Keycache to be initialized.
[1956] kf.config.core: Use of KConfigWatcher without DBus support. You will not receive updates
[1956] org.kde.pim.kleopatra: Startup timing: 4758 ms: MainWindow created
[1956] org.kde.pim.kleopatra: open_or_raise showing window
[1956] org.kde.pim.kleopatra: you need to register view Kleo::NavigatableTreeView(0x46c6430, name="m_view") before trying to set it as the current view!
[1956] org.kde.pim.kleopatra: Startup timing: 5118 ms: MainWindow raised
[1956] org.kde.pim.libkleo: gpg4winVersionNumber returns "3.1.27-beta26"
[1956] org.kde.pim.kleopatra: No update for: "3.1.27-beta26"
[1956] org.kde.pim.kleopatra: Startup timing: 5252 ms: /home/aheinecke/dev/main/src/gpg4win/src/playground/build/kleopatra-202212211440/src/kleopatraapplication.cpp openOrRaiseMainWindow 701
[1956] org.kde.pim.kleopatra: Startup timing: 5253 ms: new instance created
[1956] org.kde.pim.kleopatra: Waiting for Keycache to be initialized.
[1956] org.kde.pim.libkleo: Reading config group "Icons"
[1956] org.kde.pim.kleopatra: 
[1956] org.kde.pim.kleopatra: 
[1956] org.kde.pim.kleopatra: ReaderStatusThread[2nd]: new iteration command= "__update__"  ; nullSlot= true
[1956] org.kde.pim.kleopatra: update_cardinfo()
[1956] org.kde.pim.libkleo: sendCommand "SCD SERIALNO"
[1956] org.kde.pim.libkleo: Connecting to the agent failed. Retrying in 125 ms
[1956] org.kde.pim.libkleo: Connecting to the agent failed. Retrying in 250 ms
[1956] org.kde.pim.libkleo: sendCommand "SCD SERIALNO" failed: No such device (code: 32848, source: SCD)
[1956] org.kde.pim.libkleo: sendStatusLinesCommand "SCD SERIALNO" : t == NULL
[1956] org.kde.pim.kleopatra: update_cardinfo: No card present

I did a little bit of testing with okular, and it kind of gives similar numbers.

First start is 2.5 times slower than the next starts. This is the case both compiled with mingw and with msvc, although a msvc compiled version is 10-20% faster in startup than a mingw compiled one. The profiling tools is supposedly better with msvc so there could be a path that way to get closer to what's up.

So, I smashed this all together. The icon subset and the cross compile patch, and my time for first startup was 5 seconds then once with procmon enabled 7 seconds and now with a reduced set of icons I am down to Kleopatra to 1.7seconds. The icon subset is just 1.4mb. With all the icons we would have installed for Okular and Kleopatra. I don't have enough time to clean this up today to push it but this looks very good.
Although I am thinking to add a way to kicontheme maybe as a global variable to provide the name for the resource file so that we can properly switch between breeze-dark and breeze.

Mmh, on further checking I notice that some icons are missing though. Need to investigate where they went. I basically just took the inst-breeze.nsi file, and removed all the NSIS things and did a sort -u on it to create the list of icons.

Ah nevermind missing icons were related because I also removed the highcolor icons for testing.

I have pushed my work from today so that the only thing remains is to update the inst-breeze / uninst-breeze nsi files and figure out what to do with breeze-dark.

aheinecke changed the task status from Open to Testing.Nov 15 2023, 9:34 AM
aheinecke changed the status of subtask T6344: Kleopatra, GPG: AboutData ctor on Windows takes too long from Open to Testing.
aheinecke added a project: vsd32.

Same as with T6344 this is already in beta-277

aheinecke claimed this task.

I'm quite happy with that now. The only thing left to do would be to benchmark this, but to keep this as a an open task for that seems wrong.

ebo edited projects, added vsd32 (vsd-3.2.0); removed vsd32.