UI::Shortcuts: Improve performance
Rework the shortcuts handling to improve startup time by ca. 0.5 seconds out of total 6 seconds. Before, Inkscape::Shortcuts::getInstance()
took 15% of the CPU time for starting Inkscape, now it is down to <1%.
Measurement method:
- Start Inkscape, Open welcome dialog, click "New Document", Close Window, wait until Inkscape exits.
- Startup time: User CPU time shown by
time inkscape
. (Assuming that CPU is the main bottleneck.) Repeat for a few times to avoid variation due to user input and IO cache. Times will of course depend on how fast your machine is. - CPU percentage: Determined via Callgrind.
- Make a debug build (Call
cmake
with-DCMAKE_BUILD_TYPE=Debug
) valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes install_dir/bin/inkscape
- Proceed as above. Look at the resulting file in KCachegrind. Suggested: disable cycle detection, check "incl." column. Increase the number of items in lists in the settings to show more functions. Set displayed value to "estimated CPU cycles".
- Percentages should be independent of how fast your machine is.
- Make a debug build (Call
- VirtualBox with Ubuntu 23.10, which means Gtk falls back to software rendering.
Technical details:
The operator ==
of Glib::ustring is very slow. Avoid it by converting to std::string
with .raw()
. Now, the comparison is much faster but no longer applies UTF8 normalization (collation). I assume that this is OK because we only compare strings generated from within Inkscape; there are no "external inputs" with badly formed UTF8.
If something is wrong with this assumption, symptoms may include duplicate, missing or incorrectly overwritten shortcuts.
Please review with care, I am not very experienced in C++. Feel welcome to throw away and rewrite :-)