Bug 501508 - UI reacts noticably slow while typing inside an open file on an NFS share
Summary: UI reacts noticably slow while typing inside an open file on an NFS share
Status: RESOLVED FIXED
Alias: None
Product: kate
Classification: Applications
Component: application (show other bugs)
Version: 24.12.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWrite Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-03-14 21:36 UTC by Marco Rebhan
Modified: 2025-03-22 16:00 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marco Rebhan 2025-03-14 21:36:31 UTC
SUMMARY
When opening a text file which is stored on an NFS mount, inputting a key has a noticable delay. Looking at nfsstat, every key press increases the "write" operation counter, and whatever this operation is is blocking the UI thread.

The same behavior happens when saving swap files is turned off and all plugins are turned off.

STEPS TO REPRODUCE
1. Open file on NFS share
2. Enter text

OBSERVED RESULT
Each key press causes causes an NFS write operation which hangs the UI for a short time

EXPECTED RESULT
UI does not hang

SOFTWARE/OS VERSIONS
Operating System: Gentoo Linux 2.17
KDE Plasma Version: 6.3.2
KDE Frameworks Version: 6.11.0
Qt Version: 6.8.2
Kernel Version: 6.13.5-gentoo-dist (64-bit)
Graphics Platform: Wayland
Processors: 24 × 13th Gen Intel® Core™ i7-13700F
Memory: 62.6 GiB of RAM
Graphics Processor: AMD Radeon RX 6800 XT
Manufacturer: Micro-Star International Co., Ltd.
Product Name: MS-7D25
System Version: 1.0
Comment 1 Christoph Cullmann 2025-03-15 19:15:34 UTC
Mnn, if the swap files are off, that is strange. It would be interesting where that happens, if you could run Kate in some profiler like 'hotspot' and tell where the most time is spend that would perhaps show the bottleneck.
Comment 2 Marco Rebhan 2025-03-15 23:32:04 UTC
(In reply to Christoph Cullmann from comment #1)
> Mnn, if the swap files are off, that is strange. It would be interesting
> where that happens, if you could run Kate in some profiler like 'hotspot'
> and tell where the most time is spend that would perhaps show the bottleneck.

Trying it again, it does seem related to the swap files, my bad. Just disabling them and testing right away doesn't work which is why I didn't catch it initially, you have to close and reopen the file for the freezes to go away after setting it to either disabled or storing them in a custom local directory.

This is strange though, since it's set to "Save swap files every 15s". Why does this setting do something on every key press?

Also, should I still attach the generated perf.data file from hotspot? Not sure I'm doing this right since I'm not seeing a relevant function. Most of the time seems to be spent in the UI drawing code in libQt6Gui and I'm not seeing any IO calls anywhere.
Comment 3 Christoph Cullmann 2025-03-16 17:00:36 UTC
Could be that io wait will not show properly in the hotspot files. Not sure why the 15 seconds setting doesn't help needs to be investigated.
Comment 4 Christoph Cullmann 2025-03-20 18:49:11 UTC
I inspected the code, I see no reason why we should flush more often than once per interval, we even use just one global timer for all files.
Comment 5 Christoph Cullmann 2025-03-20 18:51:00 UTC
We do flush after each edit. We sync on each sync interval.
Comment 6 Christoph Cullmann 2025-03-20 19:05:02 UTC
We could try to move the flush to the place we sync.
Comment 7 Christoph Cullmann 2025-03-20 19:13:26 UTC
I will take a look.
Comment 8 Christoph Cullmann 2025-03-20 19:28:02 UTC
https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/798

Can you test that branch?
Comment 9 Marco Rebhan 2025-03-21 23:09:38 UTC
(In reply to Christoph Cullmann from comment #8)
> https://invent.kde.org/frameworks/ktexteditor/-/merge_requests/798
> 
> Can you test that branch?

I applied the patch to ktexteditor 6.12.0 and looks like that fixes it.

I realized I could turn on NFS debugging to look at the operations, and there:

Without the patch (one write for each character typed):

> [ 4218.028400] NFS: fsync file(saiko/.Test.txt.kate-swp) datasync 1
> [ 4218.031784] NFS: write(saiko/.Test.txt.kate-swp, 16@20494)
> [ 4218.119789] NFS: write(saiko/.Test.txt.kate-swp, 16@20510)
> [ 4218.178227] NFS: write(saiko/.Test.txt.kate-swp, 16@20526)
> [ 4218.228303] NFS: write(saiko/.Test.txt.kate-swp, 16@20542)
> ...
> [ 4232.747619] NFS: write(saiko/.Test.txt.kate-swp, 16@24622)
> [ 4232.892042] NFS: write(saiko/.Test.txt.kate-swp, 16@24638)
> [ 4233.039792] NFS: write(saiko/.Test.txt.kate-swp, 16@24654)
> [ 4233.139649] NFS: fsync file(saiko/.Test.txt.kate-swp) datasync 1

With the patch (every 15s only right before the fsync):

> [ 4372.943790] NFS: write(saiko/.Test.txt.kate-swp, 6864@5422)
> [ 4373.150276] NFS: fsync file(saiko/.Test.txt.kate-swp) datasync 1
> [ 4387.943589] NFS: write(saiko/.Test.txt.kate-swp, 6496@12286)
> [ 4388.170490] NFS: fsync file(saiko/.Test.txt.kate-swp) datasync 1

Thanks!
Comment 10 Christoph Cullmann 2025-03-22 14:44:52 UTC
Git commit 13972aefd78ccb25a85318f6ebd0afac0b191ab0 by Christoph Cullmann.
Committed on 22/03/2025 at 14:44.
Pushed by cullmann into branch 'master'.

Try to flush less often to disk

Bundles flush with sync, avoid stall on nfs.

M  +8    -8    src/swapfile/kateswapfile.cpp

https://invent.kde.org/frameworks/ktexteditor/-/commit/13972aefd78ccb25a85318f6ebd0afac0b191ab0
Comment 11 Christoph Cullmann 2025-03-22 16:00:13 UTC
Thanks for testing this.