Bug 468461

Summary: Adding to the KRecentDocument::add cant take up to 100ms
Product: [Frameworks and Libraries] frameworks-kio Reporter: Méven Car <meven29>
Component: generalAssignee: KIO Bugs <kio-bugs-null>
Status: CONFIRMED ---    
Severity: normal CC: kdelibs-bugs, nate, waqar.17a
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
See Also: https://bugs.kde.org/show_bug.cgi?id=420504
Latest Commit: Version Fixed In:

Description Méven Car 2023-04-13 09:49:33 UTC
Since now KRecentDocument::add parses and add data to an xml files, it can take up to 100ms to do its work.

We need to make it not slow down main thread.

Using a separate thread makes sense, using a daemon with temporary files could make sense. 

This caused kate to remove use of `KRecentDocument::add` https://invent.kde.org/utilities/kate/-/commit/18dc91a1e6d29aad27072963a12d960517f9da1b
Relates to 420504.
Comment 1 Waqar Ahmed 2023-04-13 19:53:28 UTC
From my profiling that I did at that time, I think the issue was that the xml file kept accumulating entries without ever removing them. So after a while the file would become large and slow down the startup of Kate. The larger the file, the slower Kate's startup. 

Imo, threads or daemon would be overkill for a such a simple job. Perhaps the recents list could be kept small. Otherwise it would help if a faster xml library for reading the data was used because QXml* is a disaster when it comes to performance.
Comment 2 Waqar Ahmed 2023-04-13 20:02:05 UTC
Checking the chat records of the discussion around this, for me the xbel file at that time was

    1.9M waqar  1 Jul 23:34 /home/waqar/.local/share/recently-used.xbel

which caused a 100ms slow down, per flie open
Comment 3 Méven Car 2023-04-14 10:31:02 UTC
(In reply to Waqar Ahmed from comment #1)
> From my profiling that I did at that time, I think the issue was that the
> xml file kept accumulating entries without ever removing them. So after a
> while the file would become large and slow down the startup of Kate. The
> larger the file, the slower Kate's startup. 
> 
> Imo, threads or daemon would be overkill for a such a simple job. Perhaps
> the recents list could be kept small. Otherwise it would help if a faster
> xml library for reading the data was used because QXml* is a disaster when
> it comes to performance.

Reducing the xml file size is one of the objective of https://invent.kde.org/frameworks/kio/-/merge_requests/1196 please review it.
This  might be enough to fix this bug. But It would need some measurement to confirm.
Comment 4 Méven Car 2023-04-14 11:52:04 UTC
(In reply to Méven Car from comment #3)
> (In reply to Waqar Ahmed from comment #1)
> > From my profiling that I did at that time, I think the issue was that the
> > xml file kept accumulating entries without ever removing them. So after a
> > while the file would become large and slow down the startup of Kate. The
> > larger the file, the slower Kate's startup. 
> > 
> > Imo, threads or daemon would be overkill for a such a simple job. Perhaps
> > the recents list could be kept small. Otherwise it would help if a faster
> > xml library for reading the data was used because QXml* is a disaster when
> > it comes to performance.
> 
> Reducing the xml file size is one of the objective of
> https://invent.kde.org/frameworks/kio/-/merge_requests/1196 please review it.
> This  might be enough to fix this bug. But It would need some measurement to
> confirm.

My plan would be to move only the trimming file size part to the daemon.
This is a lot slower than adding an entry to the file.