Discussion:
cc-mode is very slow when open cpp file with big macro
Zhongwei Yao
2017-06-27 15:01:32 UTC
Permalink
Hi, all,

When I open the following file with Emacs (25.2.1) on Mac, Emacs will get
stuck for about more than 10 seconds:

http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cp

And the profiler info shows cc-mode "c-backward-sws" is the hotspot. And
after check cc-mode's doc, I find font-lock-maximum-decoration to 1 will
result in much better performance. But I lose the fancy font and color in
my source file. Do you have any suggestions to solve this issue?

Thanks.


== profiler info start ==
- linum-update-current 6948 93%
- linum-update 6948 93%
- mapc 6948 93%
- linum-update-window 6948 93%
- window-end 6947 93%
- jit-lock-function 6947 93%
- jit-lock-fontify-now 6947 93%
- jit-lock--run-functions 6911 93%
- run-hook-wrapped 6911 93%
- #<compiled 0x44020c99> 6911 93%
- font-lock-fontify-region 6911 93%
- c-font-lock-fontify-region 6911 93%
- font-lock-default-fontify-region 6883 92%
- font-lock-fontify-keywords-region 6882 92%
- c-font-lock-declarations 6768 91%
- c-find-decl-spots 6768 91%
- #<compiled 0x404adfd9> 6758 91%
- c-backward-over-enum-header 6440 86%
- c-backward-typed-enum-colon 6344 85%
- c-backward-token-2 6271 84%
c-backward-sws 5732 77%
c-beginning-of-current-token 14 0%
+ c-backward-token-2 73 0%
c-on-identifier 7 0%
+ c-back-over-member-initializers 68 0%
+ c-forward-decl-or-cast-1 59 0%
+ c-forward-label 55 0%
+ c-beginning-of-decl-1 51 0%
+ c-parse-state 31 0%
c-backward-sws 20 0%
c-determine-limit 5 0%
+ c-cheap-inside-bracelist-p 5 0%
c-backward-token-2 3 0%
c-on-identifier 1 0%
+ c-forward-token-2 1 0%
+ #<compiled 0x40a9d625> 81 1%
+ c-font-lock-complex-decl-prepare 19 0%
+ c-font-lock-enclosing-decls 7 0%
+ c-font-lock-enum-tail 2 0%
#<compiled 0x40a9d4ed> 2 0%
#<compiled 0x40a9d4d1> 1 0%
+ font-lock-fontify-syntactically-region 1
0%
+ c-before-context-fl-expand-region 28 0%
#<compiled 0x412cccd5> 36 0%
== profiler info end==

--
Best regards,
Zhongwei
Alan Mackenzie
2017-06-27 17:36:53 UTC
Permalink
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, all,
When I open the following file with Emacs (25.2.1) on Mac, Emacs will get
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cp
I tried to download this file, but got a server error which looked like
"file not found". How big is the file? If it's really not that big
(perhaps up to about 30k), please post it here on the list. Otherwise,
would you please either sort out the server problem, or put it up
somewhere else on the net, or (as a last resort) feel free to send it to
me privately.
Post by Zhongwei Yao
And the profiler info shows cc-mode "c-backward-sws" is the hotspot. And
after check cc-mode's doc, I find font-lock-maximum-decoration to 1 will
result in much better performance. But I lose the fancy font and color in
my source file. Do you have any suggestions to solve this issue?
This will need some analysis, which might be quite involved. I can't
promise any improvement, but I'll do my best, once I get a copy of the
file with that macro.
Post by Zhongwei Yao
Thanks.
[ .... ]
Post by Zhongwei Yao
--
Best regards,
Zhongwei
--
Alan Mackenzie (Nuremberg, Germany).
Zhongwei Yao
2017-06-27 22:58:40 UTC
Permalink
Hi, Alan, thanks for your reply!

I forget to check the URL, here is the file:
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cpp

(also attached)
Post by Alan Mackenzie
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, all,
When I open the following file with Emacs (25.2.1) on Mac, Emacs will get
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cp
I tried to download this file, but got a server error which looked like
"file not found". How big is the file? If it's really not that big
(perhaps up to about 30k), please post it here on the list. Otherwise,
would you please either sort out the server problem, or put it up
somewhere else on the net, or (as a last resort) feel free to send it to
me privately.
Post by Zhongwei Yao
And the profiler info shows cc-mode "c-backward-sws" is the hotspot. And
after check cc-mode's doc, I find font-lock-maximum-decoration to 1 will
result in much better performance. But I lose the fancy font and color in
my source file. Do you have any suggestions to solve this issue?
This will need some analysis, which might be quite involved. I can't
promise any improvement, but I'll do my best, once I get a copy of the
file with that macro.
Post by Zhongwei Yao
Thanks.
[ .... ]
Post by Zhongwei Yao
--
Best regards,
Zhongwei
--
Alan Mackenzie (Nuremberg, Germany).
Alan Mackenzie
2017-07-02 14:44:10 UTC
Permalink
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, Alan, thanks for your reply!
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cpp
(also attached)
Thanks, I've got it.
Post by Zhongwei Yao
Post by Alan Mackenzie
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, all,
When I open the following file with Emacs (25.2.1) on Mac, Emacs will get
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cp
Post by Zhongwei Yao
And the profiler info shows cc-mode "c-backward-sws" is the hotspot. And
after check cc-mode's doc, I find font-lock-maximum-decoration to 1 will
result in much better performance. But I lose the fancy font and color in
my source file. Do you have any suggestions to solve this issue?
This will need some analysis, which might be quite involved. I can't
promise any improvement, but I'll do my best, once I get a copy of the
file with that macro.
OK. For problems like this, I use my function `time-scroll', which times
the scrolling of a file to the finish (or to the start), and is a useful
check on fontification timings:

(defmacro time-it (&rest forms)
"Time the running of a sequence of forms using `float-time'.
Call like this: \"M-: (time-it (foo ...) (bar ...) ...)\"."
`(let ((start (float-time)))
,@forms
(- (float-time) start)))

(defun time-scroll (&optional arg)
(interactive "P")
(message "%s"
(time-it
(condition-case nil
(while t
(if arg (scroll-down) (scroll-up))
(sit-for 0))
(error nil)))))

To use it, simply do M-: (time-scroll), or M-: (time-scroll t) to scroll
backwards. Between runs of `time-scroll' it is useful to go to the
beginning of the file, type a character then undo the change. This
clears the caches of fontification information.

When I run `time-scroll' on your file in Emacs-25.2, it takes around
109s. On a repository head (either CC Mode's repo, or Emacs's at
savannah) it takes around 10s. This is a speed up of a factor of ~10,
and was caused by a commit on 2016-07-03 "Remove redundant forms from CC
Mode for faster fontification".

The 10s it takes to scroll ~950 lines of code is not that great, but it
is considerably better than 109s.

Can I ask you, at this point, to download a repository head. Either that
of Emacs from the GNU savannah server (if you need to ask how to do this,
it probably isn't a good idea) or from the CC Mode repository at Source
Forge. The instructions for getting the CC Mode repository can be read
at <http://cc-mode.sourceforge.net/hgaccess.php>.

This should, at least, help you to get through the day with an only
moderately slow CC Mode. Perhaps, then, we can discuss whether any
further optimisations are needed to handle C++ files like the one you
sent me.
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
Thanks.
--
Best regards,
Zhongwei
--
Alan Mackenzie (Nuremberg, Germany).
Zhongwei Yao
2017-07-04 06:00:38 UTC
Permalink
Hi, Alan,
I've tried the CC Mode from the repository at Source Forge. It is better
now and becomes usable for my "vmStructs_jvmci.cpp" file! Thanks a lot!
Post by Alan Mackenzie
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, Alan, thanks for your reply!
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cpp
(also attached)
Thanks, I've got it.
Post by Zhongwei Yao
Post by Alan Mackenzie
Hello, Zhongwei.
Post by Zhongwei Yao
Hi, all,
When I open the following file with Emacs (25.2.1) on Mac, Emacs
will get
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
http://hg.openjdk.java.net/jdk10/jdk10/hotspot/file/
7a8840999420/src/share/vm/jvmci/vmStructs_jvmci.cp
Post by Zhongwei Yao
And the profiler info shows cc-mode "c-backward-sws" is the hotspot.
And
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
after check cc-mode's doc, I find font-lock-maximum-decoration to 1
will
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
result in much better performance. But I lose the fancy font and
color in
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
my source file. Do you have any suggestions to solve this issue?
This will need some analysis, which might be quite involved. I can't
promise any improvement, but I'll do my best, once I get a copy of the
file with that macro.
OK. For problems like this, I use my function `time-scroll', which times
the scrolling of a file to the finish (or to the start), and is a useful
(defmacro time-it (&rest forms)
"Time the running of a sequence of forms using `float-time'.
Call like this: \"M-: (time-it (foo ...) (bar ...) ...)\"."
`(let ((start (float-time)))
(- (float-time) start)))
(defun time-scroll (&optional arg)
(interactive "P")
(message "%s"
(time-it
(condition-case nil
(while t
(if arg (scroll-down) (scroll-up))
(sit-for 0))
(error nil)))))
To use it, simply do M-: (time-scroll), or M-: (time-scroll t) to scroll
backwards. Between runs of `time-scroll' it is useful to go to the
beginning of the file, type a character then undo the change. This
clears the caches of fontification information.
When I run `time-scroll' on your file in Emacs-25.2, it takes around
109s. On a repository head (either CC Mode's repo, or Emacs's at
savannah) it takes around 10s. This is a speed up of a factor of ~10,
and was caused by a commit on 2016-07-03 "Remove redundant forms from CC
Mode for faster fontification".
The 10s it takes to scroll ~950 lines of code is not that great, but it
is considerably better than 109s.
Can I ask you, at this point, to download a repository head. Either that
of Emacs from the GNU savannah server (if you need to ask how to do this,
it probably isn't a good idea) or from the CC Mode repository at Source
Forge. The instructions for getting the CC Mode repository can be read
at <http://cc-mode.sourceforge.net/hgaccess.php>.
This should, at least, help you to get through the day with an only
moderately slow CC Mode. Perhaps, then, we can discuss whether any
further optimisations are needed to handle C++ files like the one you
sent me.
Post by Zhongwei Yao
Post by Alan Mackenzie
Post by Zhongwei Yao
Thanks.
--
Best regards,
Zhongwei
--
Alan Mackenzie (Nuremberg, Germany).
Loading...