php-mode
php-mode copied to clipboard
Poor performance when `display-line-numbers` is set to `visual`
When using php-mode, if display-line-numbers is set to 'visual then the performance when typing is very poor. The problem gets worse proportionally to the number of buffer lines; in my case it becomes noticeable when the buffer gets to around 30 lines.
Here is a profile when set to 'visual: -
- command-execute 291 88%
- call-interactively 291 88%
- funcall-interactively 291 88%
- self-insert-command 273 82%
- c-after-change 138 41%
- c-trim-found-types 138 41%
- c-beginning-of-current-token 138 41%
- skip-syntax-backward 138 41%
- internal--syntax-propertize 138 41%
- syntax-propertize 138 41%
- php-syntax-propertize-function 138 41%
- php-syntax-propertize-hash-line-comment 138 41%
- move-beginning-of-line 137 41%
- line-move 137 41%
line-move-1 137 41%
- electric-pair-post-self-insert-function 135 41%
- electric-pair-syntax-info 135 41%
- syntax-ppss 135 41%
- parse-partial-sexp 135 41%
- internal--syntax-propertize 135 41%
- syntax-propertize 135 41%
- php-syntax-propertize-function 135 41%
- php-syntax-propertize-hash-line-comment 134 40%
- move-beginning-of-line 134 40%
- line-move 134 40%
line-move-1 134 40%
+ counsel-M-x 18 5%
Here is a profile when set to 'relative: -
- command-execute 75 70%
- call-interactively 75 70%
- funcall-interactively 75 70%
- self-insert-command 55 51%
- electric-pair-post-self-insert-function 29 27%
- electric-pair-syntax-info 29 27%
- syntax-ppss 29 27%
- parse-partial-sexp 29 27%
- internal--syntax-propertize 29 27%
- syntax-propertize 29 27%
- php-syntax-propertize-function 29 27%
- php-syntax-propertize-hash-line-comment 29 27%
- move-beginning-of-line 29 27%
- line-move 29 27%
- line-move-1 29 27%
- vertical-motion 4 3%
- jit-lock-function 4 3%
- jit-lock-fontify-now 4 3%
- jit-lock--run-functions 4 3%
- run-hook-wrapped 4 3%
- #<compiled 0x157529864965> 4 3%
- font-lock-fontify-region 4 3%
- c-font-lock-fontify-region 4 3%
- font-lock-default-fontify-region 3 2%
- font-lock-fontify-keywords-region 2 1%
- #<compiled 0x1575295055fd> 1 0%
- c-beginning-of-decl-1 1 0%
- c-beginning-of-statement-1 1 0%
c-beginning-of-macro 1 0%
- c-before-context-fl-expand-region 1 0%
- mapc 1 0%
- #<compiled 0x157529228b15> 1 0%
- c-context-expand-fl-region 1 0%
- c-fl-decl-end 1 0%
c-backward-sws 1 0%
- c-after-change 26 24%
- c-trim-found-types 26 24%
- c-beginning-of-current-token 26 24%
- skip-syntax-backward 26 24%
- internal--syntax-propertize 26 24%
- syntax-propertize 26 24%
- php-syntax-propertize-function 26 24%
- php-syntax-propertize-hash-line-comment 26 24%
- move-beginning-of-line 26 24%
- line-move 26 24%
line-move-1 25 23%
+ counsel-M-x 19 17%
+ evil-normal-state 1 0%
+ ... 30 28%
+ redisplay_internal (C function) 1 0%
+ timer-event-handler 1 0%
I am using GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28
I confirm this issue, but for me performance is very bad (seconds lag on typing) even when display line numbers is disabled, especially when typing inside strings. My profile:
- command-execute 585 88%
- call-interactively 584 87%
- funcall-interactively 584 87%
- self-insert-command 578 87%
- c-after-change 479 72%
- mapc 270 40%
- #<compiled 0x156f74ae2ae9> 270 40%
- c-after-change-mark-abnormal-strings 270 40%
- c-multiline-string-check-final-quote 270 40%
- c-literal-limits 270 40%
- c-full-pp-to-literal 270 40%
- c-parse-ps-state-below 266 40%
- parse-partial-sexp 266 40%
- internal--syntax-propertize 266 40%
- syntax-propertize 266 40%
- php-syntax-propertize-function 263 39%
- php-syntax-propertize-hash-line-comment 253 38%
- move-beginning-of-line 253 38%
- line-move 252 37%
- line-move-1 251 37%
+ vertical-motion 197 29%
+ #<compiled 0x156f7555b0e1> 2 0%
- php-syntax-propertize-quotes-in-comment 10 1%
syntax-ppss 10 1%
php-syntax-propertize-extend-region 1 0%
- parse-partial-sexp 4 0%
- internal--syntax-propertize 4 0%
- syntax-propertize 4 0%
- php-syntax-propertize-function 4 0%
- php-syntax-propertize-hash-line-comment 4 0%
- move-beginning-of-line 4 0%
- line-move 4 0%
line-move-1 4 0%
- c-trim-found-types 208 31%
- c-beginning-of-current-token 208 31%
- skip-syntax-backward 208 31%
- internal--syntax-propertize 208 31%
- syntax-propertize 208 31%
- php-syntax-propertize-extend-region 165 24%
- re-search-backward 165 24%
- internal--syntax-propertize 165 24%
- syntax-propertize 165 24%
+ php-syntax-propertize-extend-region 94 14%
+ php-syntax-propertize-function 71 10%
+ php-syntax-propertize-function 43 6%
+ #<compiled 0x156f74aa9dad> 1 0%
+ sp--post-self-insert-hook-handler 95 14%
+ c-before-change 4 0%
+ evil-normal-state 4 0%
+ doom/toggle-profiler 2 0%
+ ... 36 5%
+ redisplay_internal (C function) 28 4%
+ evil-escape-pre-command-hook 7 1%
+ timer-event-handler 3 0%
+ evil-repeat-pre-hook 1 0%
+ evil-repeat-post-hook 1 0%
+ jit-lock--antiblink-post-command 1 0%
+ company-post-command 1 0%
+ evil--jump-hook 1 0%
commenting the following solved the performance issues, although I don't know at what cost:
(defun php-syntax-propertize-function (start end)
"Apply propertize rules from START to END."
;; (goto-char start)
;; (while (and (< (point) end)
;; (re-search-forward php-heredoc-start-re end t))
;; (php-heredoc-syntax))
;; (goto-char start)
;; (while (re-search-forward "['\"]" end t)
;; (when (php-in-comment-p)
;; (c-put-char-property (match-beginning 0)
;; 'syntax-table (string-to-syntax "_"))))
)
I can confirm too that I have problems typing inside of string delimiters even with display-line-numbers-mode disabled.
Just temporarily (as I haven't had time to debug this properly yet), I've removed all functions from php-syntax-propertize-functions like so: -
(setq php-syntax-propertize-functions '()))
Now there's no delay when typing with or without line numbers. Of course, these functions serve a purpose so I'm assuming some syntax highlighting will no longer work.