Fix 100% CPU on startup with large clipboard history#49
Fix 100% CPU on startup with large clipboard history#49EricBlanquer wants to merge 1 commit intodiodon-dev:masterfrom
Conversation
|
Thanks for your contribution. Can you send me the prompts you used to generate this PR? that would be very helpful. |
|
Hi @sliverc Me:
Claude response:
Me:
Claude response:
|
|
Thanks a lot. This is very helpful. In Diodon did you activate "add images to clipboard histroy' setting? Do you remember? By default it is turned off. |
|
yes @sliverc
|
|
OK most likely images are causing the problem. Question: You wrote in the prompt that "diodon stopped working". What did you noticed that it stopped working? It would not start at all or taking a long time? Or was their another problem when opening the menu...? |
TextClipboardItem.get_label() processes the entire text through PCRE2 regex (via Vala's string.replace() -> g_regex_replace_literal()) before truncating to 50 characters. For large clipboard items (e.g. 74KB), this causes excessive CPU usage. Fix: truncate early and use split/join instead of regex-based replacement. ImageClipboardItem.with_payload() fully decodes each PNG payload into a Gdk.Pixbuf on construction. When loading 50 recent items including multiple 100KB-1MB screenshots, this decodes tens of MB of PNG data on every menu rebuild. Fix: defer pixbuf decoding until actually needed (paste, icon display), keeping only the raw payload in memory.
|
Diodon was running in the background but completely unresponsive. The keyboard shortcut (Super+V) would not open the menu at all. Command-line verification showed the diodon process was consuming 100% CPU permanently (not just temporarily during startup). |
01720ec to
b66e001
Compare
|
Thanks. I assume copying of a large image caused this. For now I recommend you disable adding images to clipboard history and I will look into it to see how to improve it. |

Problem
On Ubuntu Noble (24.04) / Linux Mint 22.3 with Cinnamon, Diodon 1.13.0 consumes 100% CPU immediately on startup when the Zeitgeist clipboard history contains many items (30+), especially large text items or images. The process never becomes idle.
GDB backtrace shows the main thread stuck in:
Root cause
Two performance issues compound into a CPU spin:
1.
TextClipboardItem.get_label()processes entire text before truncating_text.replace("\n", " ")compiles (via Vala) tog_regex_replace_literal(), which runs the entire string through PCRE2. For large clipboard items (found a 74KB text item), this is extremely wasteful since only 50 characters are displayed.2.
ImageClipboardItem.with_payload()fully decodes PNG on constructionEvery image is decoded from PNG into a
Gdk.Pixbufimmediately when loaded from Zeitgeist. With 50 recent items including multiple 100KB–1MB PNG screenshots, this decodes tens of MB of PNG data on every menu rebuild.Fix
Text items: Truncate the string early (200 bytes max) before processing, and use
split()/joinv()instead of regex-basedreplace().Image items: Defer
Gdk.Pixbufdecoding until the pixbuf is actually needed (paste, icon display). Keep only the raw payload in memory after extracting dimensions and checksum.Testing
meson setup build && ninja -C buildcompiles without errorsWorkaround (without this fix)