Issue #336
Incredibly slow Indenting
| Status: | Assigned | Start date: | 03/23/2011 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | Michael McNamara | % Done: | 0% |
|
| Category: | - | |||
| Target version: | - |
History
Updated by Jonathan Greenlaw about 2 years ago
We are seeing some REALLY long times after hitting return in certain files. Below are two breakpoints.
Xemacs [version 21.5.29 of May 2009] verilog-mode-670
Debugger entered--Lisp error: (quit)
parse-partial-sexp(1 278360)
verilog-syntax-ppss()
(save-excursion (verilog-syntax-ppss))
(let ((state ...)) (> (nth 0 state) 0))
verilog-in-paren()
(and (equal (char-after) ?}) (verilog-in-paren))
(if (and (equal ... ?}) (verilog-in-paren)) (save-excursion (verilog-backward-ws&directives) (if ... ... nil)))
verilog-at-close-constraint-p()
(let ((there ...)) (if there (progn ... ... ...)))
(cond ((equal ... ?{) (if ... ...)) ((equal ... ?}) (let ... ...)) ((looking-at verilog-beg-block-re-ordered) (cond ... ... ... ... ... ...)) ((looking-at verilog-end-block-re) (verilog-leap-to-head) (if ... ...)) ((looking-at verilog-defun-level-re) (if ... ... ...)) ((looking-at verilog-cpp-level-re) (throw ... ...)) ((bobp) (throw ... ...)))
(catch (quote continue) (cond (... ...) (... ...) (... ...) (... ... ...) (... ...) (... ...) (... ...)))
(while (verilog-re-search-backward re nil (quote move)) (catch (quote continue) (cond ... ... ... ... ... ... ...)))
(let ((re ...)) (while (verilog-re-search-backward re nil ...) (catch ... ...)) (throw (quote nesting) (quote cpp)))
(catch (quote nesting) (let (...) (while ... ...) (throw ... ...)))
verilog-calc-1()
(throw (quote nesting) (verilog-calc-1))
(while t (if (bobp) (throw ... ...)) (if (verilog-continued-line-1 lim) (let ... ... ...) (goto-char starting_position)) (if (looking-at "\\<else\\>") (let ... ...)) (throw (quote nesting) (verilog-calc-1)))
(catch (quote nesting) (if (verilog-in-star-comment-p) (throw ... ...)) (if (save-excursion ... ...) (throw ... ...)) (if (verilog-in-struct-p) (throw ... ...)) (if (and verilog-indent-lists ... ...) (progn ... ...)) (while t (if ... ...) (if ... ... ...) (if ... ...) (throw ... ...)))
(let* ((starting_position ...) (par 0) (begin ...) (lim ...) (type ...)) (if (not type) (setq type ...)) (if (> par 0) (list ... par) (cond ... ... ... ...)))
(save-excursion (let* (... ... ... ... ...) (if ... ...) (if ... ... ...)))
verilog-calculate-indent()
(verilog-do-indent (verilog-calculate-indent))
verilog-indent-line()
(if verilog-auto-indent-on-newline (verilog-indent-line))
(cond ((nth 7 state) (if ... ... ...) (verilog-indent-line)) ((nth 4 state) (newline) (verilog-more-comment)) ((eolp) (if ... ... ...) (if verilog-auto-indent-on-newline ...)) (t (newline)))
(let ((state ...)) (cond (... ... ...) (... ... ...) (... ... ...) (t ...)))
(lambda (&optional arg) "Terminate line and indent next line.\nWith optional ARG, remove existing end of line comments." (interactive) (let (...) (cond ... ... ... ...)))()
call-interactively(electric-verilog-terminate-line)
recursive-edit()
debug(error (quit))
re-search-backward("//\\s-*.*\\s-*\\(translate\\|coverage\\|lint\\)_\\(on\\|off\\)\\>" nil t)
(save-excursion (re-search-backward (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>") nil t))
(and (save-excursion (re-search-backward ... nil t)) (equal "off" (match-string 2)) (point))
verilog-within-translate-off()
(and verilog-highlight-translate-off (verilog-within-translate-off))
(cond ((and verilog-highlight-translate-off ...) (verilog-back-to-start-translate-off ...)) ((looking-at verilog-directive-re-1) (point)) (t nil))
(save-excursion (beginning-of-line) (cond (... ...) (... ...) (t nil)))
(setq p (save-excursion (beginning-of-line) (cond ... ... ...)))
(while (/= here (point)) (setq here (point)) (verilog-skip-backward-comments) (setq p (save-excursion ... ...)) (if p (goto-char p)))
(progn (let (...) (cond ... ...)) (narrow-to-region bound (point)) (while (/= here ...) (setq here ...) (verilog-skip-backward-comments) (setq p ...) (if p ...)))
(if (< bound (point)) (progn (let ... ...) (narrow-to-region bound ...) (while ... ... ... ... ...)))
(let* ((bound ...) (here bound) (p nil)) (if (< bound ...) (progn ... ... ...)))
(save-restriction (let* (... ... ...) (if ... ...)))
verilog-backward-ws&directives()
(save-excursion (verilog-backward-ws&directives) (if (equal ... ?\;) (point) nil))
(if (and (equal ... ?}) (verilog-in-paren)) (save-excursion (verilog-backward-ws&directives) (if ... ... nil)))
verilog-at-close-constraint-p()
(let ((there ...)) (if there (progn ... ... ...)))
(cond ((equal ... ?{) (if ... ...)) ((equal ... ?}) (let ... ...)) ((looking-at verilog-beg-block-re-ordered) (cond ... ... ... ... ... ...)) ((looking-at verilog-end-block-re) (verilog-leap-to-head) (if ... ...)) ((looking-at verilog-defun-level-re) (if ... ... ...)) ((looking-at verilog-cpp-level-re) (throw ... ...)) ((bobp) (throw ... ...)))
(catch (quote continue) (cond (... ...) (... ...) (... ...) (... ... ...) (... ...) (... ...) (... ...)))
(while (verilog-re-search-backward re nil (quote move)) (catch (quote continue) (cond ... ... ... ... ... ... ...)))
(let ((re ...)) (while (verilog-re-search-backward re nil ...) (catch ... ...)) (throw (quote nesting) (quote cpp)))
(catch (quote nesting) (let (...) (while ... ...) (throw ... ...)))
verilog-calc-1()
(throw (quote nesting) (verilog-calc-1))
(while t (if (bobp) (throw ... ...)) (if (verilog-continued-line-1 lim) (let ... ... ...) (goto-char starting_position)) (if (looking-at "\\<else\\>") (let ... ...)) (throw (quote nesting) (verilog-calc-1)))
(catch (quote nesting) (if (verilog-in-star-comment-p) (throw ... ...)) (if (save-excursion ... ...) (throw ... ...)) (if (verilog-in-struct-p) (throw ... ...)) (if (and verilog-indent-lists ... ...) (progn ... ...)) (while t (if ... ...) (if ... ... ...) (if ... ...) (throw ... ...)))
(let* ((starting_position ...) (par 0) (begin ...) (lim ...) (type ...)) (if (not type) (setq type ...)) (if (> par 0) (list ... par) (cond ... ... ... ...)))
(save-excursion (let* (... ... ... ... ...) (if ... ...) (if ... ... ...)))
verilog-calculate-indent()
(verilog-do-indent (verilog-calculate-indent))
verilog-indent-line()
(if verilog-auto-indent-on-newline (verilog-indent-line))
(cond ((nth 7 state) (if ... ... ...) (verilog-indent-line)) ((nth 4 state) (newline) (verilog-more-comment)) ((eolp) (if ... ... ...) (if verilog-auto-indent-on-newline ...)) (t (newline)))
(let ((state ...)) (cond (... ... ...) (... ... ...) (... ... ...) (t ...)))
(lambda (&optional arg) "Terminate line and indent next line.\nWith optional ARG, remove existing end of line comments." (interactive) (let (...) (cond ... ... ... ...)))()
Debugger entered--Lisp error: (quit)
re-search-backward("//\\s-*.*\\s-*\\(translate\\|coverage\\|lint\\)_\\(on\\|off\\)\\>" nil t)
(save-excursion (re-search-backward (concat "//\\s-*.*\\s-*" verilog-directive-regexp "\\(on\\|off\\)\\>") nil t))
(and (save-excursion (re-search-backward ... nil t)) (equal "off" (match-string 2)) (point))
verilog-within-translate-off()
(and verilog-highlight-translate-off (verilog-within-translate-off))
(cond ((and verilog-highlight-translate-off ...) (verilog-back-to-start-translate-off ...)) ((looking-at verilog-directive-re-1) (point)) (t nil))
(save-excursion (beginning-of-line) (cond (... ...) (... ...) (t nil)))
(setq p (save-excursion (beginning-of-line) (cond ... ... ...)))
(while (/= here (point)) (setq here (point)) (verilog-skip-backward-comments) (setq p (save-excursion ... ...)) (if p (goto-char p)))
(progn (let (...) (cond ... ...)) (narrow-to-region bound (point)) (while (/= here ...) (setq here ...) (verilog-skip-backward-comments) (setq p ...) (if p ...)))
(if (< bound (point)) (progn (let ... ...) (narrow-to-region bound ...) (while ... ... ... ... ...)))
(let* ((bound ...) (here bound) (p nil)) (if (< bound ...) (progn ... ... ...)))
(save-restriction (let* (... ... ...) (if ... ...)))
verilog-backward-ws&directives()
(progn (backward-char 1) (verilog-backward-ws&directives) (equal (char-before) ?\;))
(and (equal (char-after) ?{) (forward-list) (progn (backward-char 1) (verilog-backward-ws&directives) (equal ... ?\;)))
(save-excursion (and (equal ... ?{) (forward-list) (progn ... ... ...)))
(if (save-excursion (and ... ... ...)) (verilog-re-search-backward "\\<constraint\\|coverpoint\\|cross\\>" nil (quote move)) nil)
verilog-at-constraint-p()
(if (verilog-at-constraint-p) (throw (quote nesting) (quote block)))
(cond ((equal ... ?{) (if ... ...)) ((equal ... ?}) (let ... ...)) ((looking-at verilog-beg-block-re-ordered) (cond ... ... ... ... ... ...)) ((looking-at verilog-end-block-re) (verilog-leap-to-head) (if ... ...)) ((looking-at verilog-defun-level-re) (if ... ... ...)) ((looking-at verilog-cpp-level-re) (throw ... ...)) ((bobp) (throw ... ...)))
(catch (quote continue) (cond (... ...) (... ...) (... ...) (... ... ...) (... ...) (... ...) (... ...)))
(while (verilog-re-search-backward re nil (quote move)) (catch (quote continue) (cond ... ... ... ... ... ... ...)))
(let ((re ...)) (while (verilog-re-search-backward re nil ...) (catch ... ...)) (throw (quote nesting) (quote cpp)))
(catch (quote nesting) (let (...) (while ... ...) (throw ... ...)))
verilog-calc-1()
(throw (quote nesting) (verilog-calc-1))
(while t (if (bobp) (throw ... ...)) (if (verilog-continued-line-1 lim) (let ... ... ...) (goto-char starting_position)) (if (looking-at "\\<else\\>") (let ... ...)) (throw (quote nesting) (verilog-calc-1)))
(catch (quote nesting) (if (verilog-in-star-comment-p) (throw ... ...)) (if (save-excursion ... ...) (throw ... ...)) (if (verilog-in-struct-p) (throw ... ...)) (if (and verilog-indent-lists ... ...) (progn ... ...)) (while t (if ... ...) (if ... ... ...) (if ... ...) (throw ... ...)))
(let* ((starting_position ...) (par 0) (begin ...) (lim ...) (type ...)) (if (not type) (setq type ...)) (if (> par 0) (list ... par) (cond ... ... ... ...)))
(save-excursion (let* (... ... ... ... ...) (if ... ...) (if ... ... ...)))
verilog-calculate-indent()
(verilog-do-indent (verilog-calculate-indent))
verilog-indent-line()
(if verilog-auto-indent-on-newline (verilog-indent-line))
(cond ((nth 7 state) (if ... ... ...) (verilog-indent-line)) ((nth 4 state) (newline) (verilog-more-comment)) ((eolp) (if ... ... ...) (if verilog-auto-indent-on-newline ...)) (t (newline)))
(let ((state ...)) (cond (... ... ...) (... ... ...) (... ... ...) (t ...)))
(lambda (&optional arg) "Terminate line and indent next line.\nWith optional ARG, remove existing end of line comments." (interactive) (let (...) (cond ... ... ... ...)))()
Updated by Wilson Snyder about 2 years ago
- Status changed from New to Assigned
- Assignee set to Michael McNamara
Updated by Benjamin Johnsen 6 months ago
I am also seeing really long times indenting files. When I run verilog-indent-buffer it takes a long time.
I have tracked it down to indent-region is calling verilog-indent-line-relative for each line. verilog-indent-line-relative calls verilog-do-indent which calls verilog-pretty-declarations-auto which calls verilog-pretty-declarations.
verilog-pretty-declarations indents all of the the declarations in the file not just the line that verilog-indent-line-relative was called on.
Since verilog-indent-buffer is calling verilog-indent-line-relative on every single line in the design when a declaration lines is called all of the declarations in the file are being indented with verilog-pretty-declarations. verilog-pretty-declarations takes a long time to run in certain files. verilog-pretty-declarations should be updated to have options to indent the whole file or only the line that is being passed.
I imagine that verilog-pretty-expr has a similar issue but haven't traced it.
Updated by Wilson Snyder 6 months ago
Thanks for the debugging. If you or someone would be willing to contribute a patch to improve this, it would be helpful.
Updated by Benjamin Johnsen 5 months ago
I took a look at this and I don't think it is going to be something simple. It looks like there is a fair bit of rework needed in the whole indent process. Even with verilog-pretty-declarations and verilog-pretty-expr disabled indenting a file can still take a while.
Here is comparison: It takes about 1 second to indent a 13838 LISP file It takes about 133 seconds to indent a 1218 line Verilog file (that is with vverilog-pretty-declarations and verilog-pretty-expr disabled)
I haven't traced it to know for sure but my guess is that since (verilog-calculate-indent) called for every single line that this function is causing a fair bit of the delay.
In summary I don't think there is a quick fix. I think it is going to a fair bit of work to speed up the indention process.
Updated by Wilson Snyder 5 months ago
Ok, hopefully we'll find time to improve it. BTW it's obviously not fair to compare a language with user defined types affecting indentation to one which can just look for the number of "(" and ";" :)
Also available in: Atom
![[logo]](/img/veripool_small.png)