D18551: clang: Create preamble only on second parse

Aaron Puchert noreply at phabricator.kde.org
Wed Oct 9 22:12:17 BST 2019


aaronpuchert added a comment.


  I still think this is the right change, but if there is no consensus I will implement @mwolff's suggestion. That would certainly be an improvement, but it doesn't really solve my problem. I'm currently working on Clang and have around 6 files open, which is really not a lot. I haven't changed any of them. The result:
  
    aaron:~/src/llvm-project> ls -l /tmp/preamble-*
    -rw-r--r-- 1 aaron users 73139496 Okt  9 22:27 /tmp/preamble-0e19f4.pch
    -rw-r--r-- 1 aaron users 59327864 Okt  9 22:23 /tmp/preamble-2a515c.pch
    -rw-r--r-- 1 aaron users 61885536 Okt  9 22:23 /tmp/preamble-2baca3.pch
    -rw-r--r-- 1 aaron users 76913424 Okt  9 22:23 /tmp/preamble-9853df.pch
    -rw-r--r-- 1 aaron users 64254872 Okt  9 22:23 /tmp/preamble-cbb035.pch
    -rw-r--r-- 1 aaron users 64829792 Okt  9 22:24 /tmp/preamble-dd9bf1.pch
    aaron:~/src/llvm-project> du -s /tmp/ 2>/dev/null
    391204  /tmp/
  
  Now I actually have `/tmp` as tmpfs, and so these 400 MB don't come for free. This is perfectly fine when I'm actually working on these files, but so far I have only opened KDevelop.
  
  In D18551#412611 <https://phabricator.kde.org/D18551#412611>, @mwolff wrote:
  
  > In D18551#410223 <https://phabricator.kde.org/D18551#410223>, @aaronpuchert wrote:
  >
  > > In D18551#409551 <https://phabricator.kde.org/D18551#409551>, @mwolff wrote:
  > >
  > > > When we didn't create the preamble, we will have to reparse the file completely. And this can easily take 1-2s per file, which is *really* annoying.
  > >
  > >
  > > It only happens on the very first edit though, and will only be noticeable if code completion is required immediately after starting to edit the file. All following parses and code completions can use the precompiled preamble then. I don't think that's too bad. It's also not unusual, many applications have something like a "warmup phase" where not everything is loaded yet.
  >
  >
  > Yes, but hiding or minimizing the warmup phase is good. And it would be possible by having the flag active for opened files like I request.
  
  
  Creating a preamble is actually more expensive than not creating it. So we make the initial parsing slower. This is only faster for files are actually edited.
  
  Creating it immediately only improves the reaction time for the first edit. For that small benefit, we're paying a hefty price.
  
  >>> Also note how we just reparsed the file solely for code completion purposes!
  >> 
  >> You mean the preamble? Since code completion is usually invoked after some initial changes, we have to reparse anyway. What you said would only be true if we invoke code completion without changing anything first, which seems rather weird.
  > 
  > I mean: We trigger a reparse when we open a document, to get hold of the clang TU to do code completion. If this *does not* create a preamble, then the following call to query code completion items - *after* editing - will create the preamble. The preamble only includes the headers of the file, not the contents of the `.cpp`.
  
  Well, then why don't we just skip the initial reparse, and only reparse after the first edit?
  
  > You usually edit the `.cpp` file and then you want to get code completion results immediately.
  
  We're talking about a one-time delay, all further edits will have a preamble.
  
  > Having a preamble is crucial for good performance here.
  
  I'm not suggesting to not create a preamble at all, but to create it only when we **know** it is needed.

REPOSITORY
  R32 KDevelop

REVISION DETAIL
  https://phabricator.kde.org/D18551

To: aaronpuchert, #kdevelop, mwolff, brauch, rjvbb
Cc: rjvbb, kdevelop-devel, hmitonneau, christiant, glebaccon, domson, antismap, iodelay, alexeymin, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20191009/bb91378e/attachment.html>


More information about the KDevelop-devel mailing list