all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: etags completion table
Date: Sat, 30 May 2015 02:58:26 +0300	[thread overview]
Message-ID: <5568FD22.4010004@yandex.ru> (raw)
In-Reply-To: <jwvr3pzqdha.fsf-monnier+emacsbugs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]

On 05/30/2015 12:41 AM, Stefan Monnier wrote:

> I see the first patch says that it takes 1.34s to build the obarray and
> 0.78s to build an equivalent list of strings, so we could change the
> code so as to keep the completion table as a pre-built list of strings
> instead of a pre-built obarray.  It will also save us a bit of memory.

Maybe. The difference isn't much, though, and it's a one-time thing.

> As for doing the search each time, the possible gain on the first
> completion (0.3s instead of 0.78s)

The possible gain is from 1.34s down to 0.78s. I haven't managed to 
bring the time to generate all completions for "" down any further.

> doesn't make up for the loss of going
> from 0.02s to 0.3s on subsequent completions.

I think you mean 0.02 to 0.2.

> So that seems like a non-starter, unless we can speed it up
> significantly.  It shouldn't be too hard to keep the worst case at
> 0.76s, but lowering the 0.3s seems harder.

Lowering 0.2 is not too hard if the prefix is at least 2-3 characters 
long: you drop [\n \t()=,;\177] from the first regexp and simply search 
for the string. This way, the search for completions for "test" takes 
only 0.05s (with 37 matches). Of course, that doesn't work at all for an 
empty prefix.

Seems like support for lookbehind in the regexp engine would help unify 
these cases.

However, the worst case is going to come up a lot. After all, that's 
what you trigger with `C-u M-. TAB'.

> Obviously we could get rid
> of the "looking-at" within the loop (fold it into the preceding
> re-search-forward), but it seems unlikely that this would gain us much
> when there are few matches.

Indeed. It brings us to 0.78 in the worst case and 0.26 in the best case 
(I'm blaming the regexp engine), with no easy opportunity for a speed-up 
when matching a longer string. Patch attached.

[-- Attachment #2: etags-completion.diff --]
[-- Type: text/x-patch, Size: 4561 bytes --]

diff --git a/lisp/progmodes/etags.el b/lisp/progmodes/etags.el
index 9ff164e..98bbabd 100644
--- a/lisp/progmodes/etags.el
+++ b/lisp/progmodes/etags.el
@@ -753,31 +753,18 @@ Assumes the tags table is the current buffer."
       (setq tags-included-tables (funcall tags-included-tables-function))))
 \f
 (defun tags-completion-table ()
-  "Build `tags-completion-table' on demand.
+  "Return tags completion table.
 The tags included in the completion table are those in the current
 tags table and its (recursively) included tags tables."
-  (or tags-completion-table
-      ;; No cached value for this buffer.
-      (condition-case ()
-	  (let (current-table combined-table)
-	    (message "Making tags completion table for %s..." buffer-file-name)
-	    (save-excursion
-	      ;; Iterate over the current list of tags tables.
-	      (while (visit-tags-table-buffer (and combined-table t))
-		;; Find possible completions in this table.
-		(setq current-table (funcall tags-completion-table-function))
-		;; Merge this buffer's completions into the combined table.
-		(if combined-table
-		    (mapatoms
-		     (lambda (sym) (intern (symbol-name sym) combined-table))
-		     current-table)
-		  (setq combined-table current-table))))
-	    (message "Making tags completion table for %s...done"
-		     buffer-file-name)
-	    ;; Cache the result in a buffer-local variable.
-	    (setq tags-completion-table combined-table))
-	(quit (message "Tags completion table construction aborted.")
-	      (setq tags-completion-table nil)))))
+  (completion-table-with-cache
+   (lambda (string)
+     (let (cont tables)
+       (save-excursion
+         ;; Iterate over the current list of tags tables.
+         (while (visit-tags-table-buffer (or cont (progn (setq cont t)  nil)))
+           ;; Find possible completions in this table.
+           (push (funcall tags-completion-table-function string) tables)))
+       (nreverse (apply #'nconc tables))))))
 
 ;;;###autoload
 (defun tags-lazy-completion-table ()
@@ -1218,7 +1205,7 @@ buffer-local values of tags table format variables."
        (mapc (lambda (elt) (set (make-local-variable (car elt)) (cdr elt)))
 	     '((file-of-tag-function . etags-file-of-tag)
 	       (tags-table-files-function . etags-tags-table-files)
-	       (tags-completion-table-function . etags-tags-completion-table)
+	       (tags-completion-table-function . etags-tags-completions)
 	       (snarf-tag-function . etags-snarf-tag)
 	       (goto-tag-location-function . etags-goto-tag-location)
 	       (find-tag-regexp-search-function . re-search-forward)
@@ -1254,35 +1241,20 @@ buffer-local values of tags table format variables."
 	  str
 	(expand-file-name str (file-truename default-directory))))))
 
-
-(defun etags-tags-completion-table () ; Doc string?
-  (let ((table (make-vector 511 0))
-	(progress-reporter
-	 (make-progress-reporter
-	  (format "Making tags completion table for %s..." buffer-file-name)
-	  (point-min) (point-max))))
+(defun etags-tags-completions (string) ; Doc string?
+  (let* (table
+         (qs (regexp-quote string))
+         (re (format (concat "[\n \t()=,;]\\(%s[^\177 \t()=,;]*\\)\177[0-9]"
+                             "\\|"
+                             "\177\\(%s[^\001]*\\)\001")
+                     qs qs)))
     (save-excursion
       (goto-char (point-min))
-      ;; This monster regexp matches an etags tag line.
-      ;;   \1 is the string to match;
-      ;;   \2 is not interesting;
-      ;;   \3 is the guessed tag name; XXX guess should be better eg DEFUN
-      ;;   \4 is not interesting;
-      ;;   \5 is the explicitly-specified tag name.
-      ;;   \6 is the line to start searching at;
-      ;;   \7 is the char to start searching at.
-      (while (re-search-forward
-	      "^\\(\\([^\177]+[^-a-zA-Z0-9_+*$:\177]+\\)?\
-\\([-a-zA-Z0-9_+*$?:]+\\)[^-a-zA-Z0-9_+*$?:\177]*\\)\177\
-\\(\\([^\n\001]+\\)\001\\)?\\([0-9]+\\)?,\\([0-9]+\\)?\n"
-	      nil t)
-	(intern	(prog1 (if (match-beginning 5)
-			   ;; There is an explicit tag name.
-			   (buffer-substring (match-beginning 5) (match-end 5))
-			 ;; No explicit tag name.  Best guess.
-			 (buffer-substring (match-beginning 3) (match-end 3)))
-		  (progress-reporter-update progress-reporter (point)))
-		table)))
+      (while (re-search-forward re nil t)
+        (push (if (match-beginning 1)
+                  (match-string-no-properties 1)
+                (match-string-no-properties 2))
+              table)))
     table))
 
 (defun etags-snarf-tag (&optional use-explicit) ; Doc string?

  reply	other threads:[~2015-05-29 23:58 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-22  5:57 bug#20629: 25.0.50; Regression: TAGS broken, can't find anything in C++ files Jan D.
2015-05-23 11:54 ` Jan Djärv
2015-05-23 12:04   ` Dmitry Gutov
2015-05-23 12:15     ` Jan Djärv
2015-05-23 12:18       ` Dmitry Gutov
2015-05-23 12:28         ` Jan Djärv
2015-05-23 12:39           ` Dmitry Gutov
2015-05-23 13:51           ` Eli Zaretskii
2015-05-23 13:50       ` Eli Zaretskii
2015-05-23 14:46         ` Eli Zaretskii
2015-05-23 15:56           ` Eli Zaretskii
2015-05-25 15:15             ` Eli Zaretskii
2015-05-25 21:17               ` Dmitry Gutov
2015-05-26  2:35                 ` Eli Zaretskii
2015-05-26 10:16                   ` Dmitry Gutov
2015-05-26 15:06                     ` Eli Zaretskii
2015-05-26 19:00                       ` Dmitry Gutov
2015-05-26 19:23                         ` Eli Zaretskii
2015-05-26 21:01                           ` Stefan Monnier
2015-05-28 11:54                             ` Dmitry Gutov
2015-05-28 12:59                               ` Dmitry Gutov
2015-05-26 23:56                           ` Dmitry Gutov
2015-05-27 14:28                             ` Eli Zaretskii
2015-05-27 15:28                               ` Dmitry Gutov
2015-05-27 15:46                                 ` Eli Zaretskii
2015-05-27 15:54                                   ` Dmitry Gutov
2015-05-27 16:23                                     ` Eli Zaretskii
2015-05-27 23:50                                       ` Dmitry Gutov
2015-05-28  2:50                                         ` Eli Zaretskii
2015-05-28 10:22                                           ` Dmitry Gutov
2015-05-28 14:56                                             ` Eli Zaretskii
2015-05-28 15:32                                               ` Dmitry Gutov
2015-05-28 16:34                                                 ` Eli Zaretskii
2015-05-29  0:09                                                   ` Dmitry Gutov
2015-05-29  6:48                                                     ` Glenn Morris
2015-05-29  8:09                                                       ` Eli Zaretskii
2015-05-29 12:34                                                         ` Francesco Potortì
2015-05-29  9:27                                                       ` Dmitry Gutov
2015-05-29  8:12                                                     ` Eli Zaretskii
2015-05-29 14:05                                                       ` Dmitry Gutov
2015-05-29 16:51                                                         ` Stefan Monnier
2015-05-29 17:12                                                           ` Dmitry Gutov
2015-05-29 19:19                                                             ` Stefan Monnier
2015-05-29 20:33                                                               ` Dmitry Gutov
2015-05-29 21:41                                                                 ` etags completion table (was: bug#20629: 25.0.50; Regression: TAGS broken, can't find anything in C++ files) Stefan Monnier
2015-05-29 23:58                                                                   ` Dmitry Gutov [this message]
2015-05-30  4:00                                                                     ` etags completion table Stefan Monnier
2015-05-30 11:50                                                                       ` Dmitry Gutov
2015-05-31  0:57                                                                         ` Stefan Monnier
2015-05-29 18:28                                                         ` bug#20629: 25.0.50; Regression: TAGS broken, can't find anything in C++ files Eli Zaretskii
2015-05-29 20:01                                                           ` Dmitry Gutov
2015-05-29 20:35                                                             ` Eli Zaretskii
2015-05-29 22:36                                                               ` Dmitry Gutov
2015-05-30  6:52                                                                 ` Eli Zaretskii
2015-05-30 12:52                                                                   ` Dmitry Gutov
2015-05-30 13:03                                                                     ` Eli Zaretskii
2015-05-30 14:21                                                                     ` Francesco Potortì
2015-05-30 14:44                                                                       ` Dmitry Gutov
2015-05-28 11:35                                   ` Francesco Potortì
2015-05-28 11:46                                     ` Dmitry Gutov
2015-05-28 12:16                                       ` Francesco Potortì
2015-05-28 13:00                                         ` Dmitry Gutov
2015-05-28 13:12                                           ` Francesco Potortì
2015-05-28 15:04                                             ` Eli Zaretskii
2015-05-28 15:14                                               ` Francesco Potortì
2015-05-28 15:29                                                 ` Francesco Potortì
2015-05-29 17:13                                                 ` Dmitry Gutov
2015-05-30 12:06                             ` Eli Zaretskii
2015-05-30 12:30                               ` Dmitry Gutov
2015-05-30 12:46                                 ` Eli Zaretskii
2015-05-30 13:42                                   ` Dmitry Gutov
2015-05-30 14:31                                     ` Eli Zaretskii
2015-05-30 15:03                                       ` Dmitry Gutov
2015-05-30 16:37                                         ` Eli Zaretskii
2015-05-30 17:46                                           ` Dmitry Gutov
2015-05-30 18:46                                             ` Eli Zaretskii
2015-05-30 19:42                                               ` Dmitry Gutov
2015-11-26  3:23                                                 ` Dmitry Gutov
2015-11-26 15:43                                                   ` Eli Zaretskii
2015-11-26 16:12                                                     ` Dmitry Gutov
2015-11-26 16:32                                                       ` Eli Zaretskii
2015-11-27  3:54                                                         ` Dmitry Gutov
2016-03-19 18:45                                                           ` Eli Zaretskii
2015-05-30 17:01                                       ` Francesco Potortì
2015-05-30 18:13                                         ` Dmitry Gutov
2015-05-30 18:42                                           ` Eli Zaretskii
2015-05-30 19:35                                           ` Francesco Potortì
2015-05-30 20:04                                             ` Dmitry Gutov
2015-05-30 22:35                                               ` Francesco Potortì
2015-05-31  0:34                                                 ` Dmitry Gutov
2015-05-31 21:46 ` bug#20629: Fwd: bug#20703: 24.4; Stack overflow in regexp matcher Francesco Potortì
2015-05-31 22:20   ` Dmitry Gutov
2015-05-31 22:40     ` Francesco Potortì

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5568FD22.4010004@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.