php-mode icon indicating copy to clipboard operation
php-mode copied to clipboard

Pasting lines is slow in large files

Open cosarara opened this issue 6 years ago • 6 comments

  1. Take any sufficiently big PHP file (slightly exaggerated example file).
  2. Open it in php-mode.
  3. Copy any line or block of code (even an empty line).
  4. Paste it. It's going to be noticeably slow. If running on a supercomputer, spam that paste chord a bit (the pastes will queue, it will take a while). Undoing the operations will be similarly slow.

The slowness is increased the bigger the file.

emacs profile

It seems like the culprit is https://github.com/emacs-php/php-mode/blob/c53e0c1ec154fcfe6e5db56d1513d503a62e0355/php-mode.el#L954 Notice there are no heredocs at all in the file.

cosarara avatar Jun 13 '19 19:06 cosarara

Commenting out the function's body makes emacs fast again (but I guess breaks heredoc things).

cosarara avatar Jun 13 '19 20:06 cosarara

@cosarara Which version of php-mode are you using (M-x php-mode-version)? Do you also experience this slowdown with the latest release (1.21.4)? Thanks!

mallt avatar Jun 14 '19 14:06 mallt

Sorry I didn't mention it, I'm using a clean emacs profile with just the latest version of php-mode installed (1.21.4 indeed). The emacs version is 26.2, from the arch linux repositories.

cosarara avatar Jun 14 '19 15:06 cosarara

@cosarara

  1. Can you show the output of M-x php-mode-debug?
  2. Does the problem occur with tcpdf.php as well?
  3. Can you provide detailed instructions, including launching and exiting the profiler?

Thank you.

zonuexe avatar Jun 19 '19 12:06 zonuexe

  1. Can you show the output of M-x php-mode-debug?
--- PHP-MODE DEBUG BEGIN ---
versions: GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.8)
 of 2019-04-12; PHP Mode 1.21.4 of 2019-05-29
package-version: nil
major-mode: php-mode
minor-modes: (tooltip-mode electric-indent-mode mouse-wheel-mode tool-bar-mode menu-bar-mode file-name-shadow-mode font-lock-mode blink-cursor-mode auto-composition-mode auto-encryption-mode auto-compression-mode line-number-mode transient-mark-mode abbrev-mode)
variables: ((indent-tabs-mode nil) (tab-width 4))
custom variables: ((php-executable /bin/php) (php-site-url https://php.net/) (php-manual-url en) (php-search-url nil) (php-class-suffix-when-insert ::) (php-namespace-suffix-when-insert \) (php-default-major-mode php-mode) (php-html-template-major-mode web-mode) (php-blade-template-major-mode web-mode) (php-template-mode-alist ((\.blade . web-mode) (\.phpt\' . php-mode) (\.phtml\' . web-mode))) (php-mode-maybe-hook nil) (php-search-documentation-browser-function nil))
c-indentation-style: pear
c-style-variables: ((c-basic-offset 4) (c-comment-only-line-offset 0) (c-indent-comment-alist ((anchored-comment column . 0) (end-block space . 1) (cpp-end-block space . 2))) (c-indent-comments-syntactically-p nil) (c-block-comment-prefix * ) (c-comment-prefix-regexp ((pike-mode . //+!?\|\**) (awk-mode . #+) (other . //+\|\**))) (c-cleanup-list (scope-operator)) (c-hanging-braces-alist ((brace-list-open) (brace-entry-open) (statement-cont) (substatement-open after) (block-close . c-snug-do-while) (extern-lang-open after) (namespace-open after) (module-open after) (composition-open after) (inexpr-class-open after) (inexpr-class-close before) (arglist-cont-nonempty))) (c-hanging-colons-alist nil) (c-hanging-semi&comma-criteria (c-semi&comma-inside-parenlist)) (c-backslash-column 48) (c-backslash-max-column 72) (c-special-indent-hook nil) (c-label-minimum-indentation 1))
c-doc-comment-style: ((java-mode . javadoc) (pike-mode . autodoc) (c-mode . gtkdoc))
c-offsets-alist: ((inexpr-class . +) (inexpr-statement . +) (lambda-intro-cont . +) (inlambda . 0) (template-args-cont c-lineup-template-args +) (incomposition . +) (inmodule . +) (innamespace . +) (inextern-lang . +) (composition-close . 0) (module-close . 0) (namespace-close . 0) (extern-lang-close . 0) (composition-open . 0) (module-open . 0) (namespace-open . 0) (extern-lang-open . 0) (objc-method-call-cont c-lineup-ObjC-method-call-colons c-lineup-ObjC-method-call +) (objc-method-args-cont . c-lineup-ObjC-method-args) (objc-method-intro . [0]) (friend . 0) (cpp-define-intro c-lineup-cpp-define +) (cpp-macro-cont . +) (cpp-macro . [0]) (inclass . +) (stream-op . c-lineup-streamop) (arglist-cont-nonempty first php-lineup-cascaded-calls c-lineup-arglist) (arglist-cont first php-lineup-cascaded-calls 0) (comment-intro . 0) (catch-clause . 0) (else-clause . 0) (do-while-closure . 0) (access-label . -) (case-label . 0) (substatement . +) (statement-case-intro . +) (statement . 0) (brace-entry-open . 0) (brace-list-entry . c-lineup-under-anchor) (brace-list-close . 0) (block-close . 0) (block-open . 0) (inher-cont . c-lineup-multi-inher) (inher-intro . +) (member-init-cont . c-lineup-multi-inher) (member-init-intro . +) (annotation-var-cont . +) (annotation-top-cont . 0) (topmost-intro . 0) (knr-argdecl . 0) (func-decl-cont . +) (inline-close . 0) (class-close . 0) (class-open . 0) (defun-block-intro . +) (defun-close . 0) (defun-open . 0) (c . c-lineup-C-comments) (string . c-lineup-dont-change) (topmost-intro-cont first php-lineup-cascaded-calls +) (brace-list-intro . +) (brace-list-open . 0) (inline-open . 0) (arglist-close . php-lineup-arglist-close) (arglist-intro . php-lineup-arglist-intro) (statement-cont first php-lineup-cascaded-calls php-lineup-string-cont +) (statement-case-open . 0) (label . +) (substatement-label . 2) (substatement-open . 0) (knr-argdecl-intro . +) (statement-block-intro . +))
--- PHP-MODE DEBUG END ---
  1. Does the problem occur with tcpdf.php as well? Yes, it does.
  2. Can you provide detailed instructions, including launching and exiting the profiler? Of course! From a clean .emacs.d to reproduction, keystroke by keystroke:
~/tmp/emacs-debugging 
> mv ~/.emacs.d ~/.emacs.d.backup
~/tmp/emacs-debugging 
> mkdir ~/.emacs.d
~/tmp/emacs-debugging 
> cat > ~/.emacs.d/init.el
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
                    (not (gnutls-available-p))))
       (proto (if no-ssl "http" "https")))
  (when no-ssl
    (warn "\
Your version of Emacs does not support SSL connections,
which is unsafe because it allows man-in-the-middle attacks.
There are two things you can do about this warning:
1. Install an Emacs version that does support SSL and be safe.
2. Remove this warning from your init file so you won't see it again."))
  ;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
  (add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
  ;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
  (when (< emacs-major-version 24)
    ;; For important compatibility libraries like cl-lib
    (add-to-list 'package-archives (cons "gnu" (concat proto "://elpa.gnu.org/packages/")))))

;; Added by Package.el.  This must come before configurations of
;; installed packages.  Don't delete this line.  If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (php-mode ##))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )
^D
~/tmp/emacs-debugging 
> emacs

Then in emacs:

M-x package-refresh-contents<RET>
M-x package-install<RET>
php-mode<RET>
C-x C-f tcpdf.php<RET>
M-x profiler-start<RET><RET> (default mode, cpu)
C-S-backspace (C-k does the trick as well)
C-y
C-y
C-y
(waaaaaaait)
M-x profiler-report

Then you need to unfold the tree (I don't know if there's a better way, but I spam <RET> and arrow down) You should end up with this: screenshot of the profiler

cosarara avatar Jun 19 '19 15:06 cosarara

@cosarara Thank you for the detailed information!

zonuexe avatar Jun 19 '19 15:06 zonuexe