Bug 369374 - Background parser slows down the GUI thread for large projects
Summary: Background parser slows down the GUI thread for large projects
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: 5.0.1
Platform: Debian unstable Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-26 09:39 UTC by Wei-Cheng Pan
Modified: 2016-11-16 23:59 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.0.3


Attachments
perf result after it start parsing C++ files (1.35 KB, application/x-bzip)
2016-09-29 11:43 UTC, Wei-Cheng Pan
Details
perf result after it start parsing C++ files (137.34 KB, application/x-bzip)
2016-10-18 06:34 UTC, Wei-Cheng Pan
Details
another hotspot (13.24 KB, application/x-bzip)
2016-10-19 03:47 UTC, Wei-Cheng Pan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wei-Cheng Pan 2016-09-26 09:39:10 UTC
I'm working on Gecko, and I found since Kdevelop 5.0, the background will make GUI very heavy.
The CPU utilization of GUI thread is very high (~100%), but other threads are nearly zero.

When I attach it to gdb, I saw many thing like this:

[New Thread 0x7f96867fc700 (LWP 16248)]
[Thread 0x7f96867fc700 (LWP 16248) exited]

Looks like it keeps create lots of short-living threads?

Reproducible: Always

Steps to Reproduce:
1. hg clone https://hg.mozilla.org/mozilla-central
2. use kdevelop 5.0.1 to open it
Comment 1 Milian Wolff 2016-09-29 07:28:26 UTC
The short living threads are used by libclang for crash resilience. You can verify whether that really is the problem by temporarily disabling that feature. For that, you will need to recompile KDevelop though, and add a call to `clang_toggleCrashRecovery(false)`, e.g. in `kdevelop/language/clang/duchain/clangindex.cpp`, before the call to `clang_CXIndex_setGlobalOptions`.

That said, I doubt that this is the reason for the high CPU usage. Could you please use a profiler to get some hard data?

- install debug symbols for kdevelop + kdevplatform
- profile CPU with perf:

perf record --call-graph dwarf --pid $(pidof kdevelop)
# wait a couple of seconds while kdevelop has high CPU usage
# ^C -> this stops the record and writes a `perf.data` file

then run

perf report --no-children -g graph | bzip2 > perf.report.bz2

and upload the report here.
Comment 2 Wei-Cheng Pan 2016-09-29 11:43:29 UTC
Created attachment 101341 [details]
perf result after it start parsing C++ files
Comment 3 Wei-Cheng Pan 2016-10-18 06:34:31 UTC
Created attachment 101612 [details]
perf result after it start parsing C++ files

Sorry, I think ther previous perf result is not right, here is the correct one (I think).

Looks like the progress events are flooding the GUI thread.
Comment 4 Wei-Cheng Pan 2016-10-18 07:37:45 UTC
I commented out this line:
m_parser->updateProgressBar();
in
KDevelop::BackgroundParserPrivate::parseDocumentsInternal

and the GUI thread becomes idle and works normally.

Maybe we can decrease the update frequency for large project?
Comment 5 KiloAlphaIndia 2016-10-18 17:41:23 UTC
I have tried commenting out that line. Honestly I don't miss anything in the progress bar (It still updates just fine).
Another benefit seams to be, that we are loosing a lot of unnecessary synchronization points for the parser threat. At least kdevelop now uses all my cores when parsing, while it previously didn't.

Is there any good reason to keep this line?
Comment 6 Wei-Cheng Pan 2016-10-19 03:47:07 UTC
Created attachment 101637 [details]
another hotspot

This report was measured after I commented out the line I mentioned before.

Looks like there is another function keeps update the progress bar. Not as busy as the one in background parser though.
Comment 7 Wei-Cheng Pan 2016-10-19 05:13:46 UTC
It's KDevelop::BackgroundParser::parseComplete emitting the signal.

We'll need to add a timer to update the progress bar, instead of notify the main thread in every single step.
Comment 8 Kevin Funk 2016-10-19 07:34:40 UTC
@Wei-Cheng: Want to get started hacking on KDevelop? Looks like you're almost there. :)

Patches welcome! See https://www.kdevelop.org/contribute-kdevelop
Comment 9 Kevin Funk 2016-11-16 23:59:14 UTC
Git commit 77e98b914694ae144fbf4c319b157b1750f729f7 by Kevin Funk, on behalf of Wei-Cheng Pan.
Committed on 16/11/2016 at 23:58.
Pushed by kfunk into branch '5.0'.

Periodically update progress bar

Summary: To avoid progress bar event flooding, adds a long-term timer to send the events periodically
FIXED-IN: 5.0.3

Reviewers: #kdevelop, kfunk

Subscribers: brauch, kfunk, kdevelop-devel

Differential Revision: https://phabricator.kde.org/D3110

M  +24   -6    language/backgroundparser/backgroundparser.cpp
M  +2    -1    language/backgroundparser/backgroundparser.h

http://commits.kde.org/kdevplatform/77e98b914694ae144fbf4c319b157b1750f729f7