Bug 468461 - Adding to the KRecentDocument::add cant take up to 100ms
Summary: Adding to the KRecentDocument::add cant take up to 100ms
Status: CONFIRMED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-13 09:49 UTC by Méven Car
Modified: 2023-04-14 11:52 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.