* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
@ 2022-11-29 14:30 yikai
2022-12-01 15:46 ` Eli Zaretskii
2022-12-02 13:44 ` Eli Zaretskii
0 siblings, 2 replies; 7+ messages in thread
From: yikai @ 2022-11-29 14:30 UTC (permalink / raw)
To: 59678; +Cc: Yikai Zhao
Hi,
I found that the auto-completion on .sh files (with company-mode) was pretty slow (takes several seconds).
It turns out that company-mode would call the capf function with 'metadata action for each candidate,
where each function call would need to list all the cmds. In this patch, I modified the code to use
completion-table-with-cache which fixes the problem for me.
---
lisp/progmodes/sh-script.el | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
index 408ebfc0451..188b3b73125 100644
--- a/lisp/progmodes/sh-script.el
+++ b/lisp/progmodes/sh-script.el
@@ -1688,19 +1688,17 @@ sh--vars-before-point
;; (defun sh--var-completion-table (string pred action)
;; (complete-with-action action (sh--vars-before-point) string pred))
-(defun sh--cmd-completion-table (string pred action)
- (let ((cmds
- (append (when (fboundp 'imenu--make-index-alist)
- (mapcar #'car
- (condition-case nil
- (imenu--make-index-alist)
- (imenu-unavailable nil))))
- (mapcar (lambda (v) (concat v "="))
- (sh--vars-before-point))
- (locate-file-completion-table
- exec-path exec-suffixes string pred t)
- sh--completion-keywords)))
- (complete-with-action action cmds string pred)))
+(defun sh--cmd-completion-table-gen (string)
+ (append (when (fboundp 'imenu--make-index-alist)
+ (mapcar #'car
+ (condition-case nil
+ (imenu--make-index-alist)
+ (imenu-unavailable nil))))
+ (mapcar (lambda (v) (concat v "="))
+ (sh--vars-before-point))
+ (locate-file-completion-table
+ exec-path exec-suffixes string nil t)
+ sh--completion-keywords))
(defun sh-completion-at-point-function ()
(save-excursion
@@ -1713,7 +1711,7 @@ sh-completion-at-point-function
(list start end (sh--vars-before-point)
:company-kind (lambda (_) 'variable)))
((sh-smie--keyword-p)
- (list start end #'sh--cmd-completion-table
+ (list start end (completion-table-with-cache #'sh--cmd-completion-table-gen)
:company-kind
(lambda (s)
(cond
--
2.38.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-11-29 14:30 bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance yikai
@ 2022-12-01 15:46 ` Eli Zaretskii
2022-12-01 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 13:44 ` Eli Zaretskii
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2022-12-01 15:46 UTC (permalink / raw)
To: yikai, Stefan Monnier; +Cc: 59678
> Cc: Yikai Zhao <yikai@z1k.dev>
> From: yikai@z1k.dev
> Date: Tue, 29 Nov 2022 22:30:14 +0800
>
> Hi,
>
> I found that the auto-completion on .sh files (with company-mode) was pretty slow (takes several seconds).
> It turns out that company-mode would call the capf function with 'metadata action for each candidate,
> where each function call would need to list all the cmds. In this patch, I modified the code to use
> completion-table-with-cache which fixes the problem for me.
Stefan, any comments?
> lisp/progmodes/sh-script.el | 26 ++++++++++++--------------
> 1 file changed, 12 insertions(+), 14 deletions(-)
>
> diff --git a/lisp/progmodes/sh-script.el b/lisp/progmodes/sh-script.el
> index 408ebfc0451..188b3b73125 100644
> --- a/lisp/progmodes/sh-script.el
> +++ b/lisp/progmodes/sh-script.el
> @@ -1688,19 +1688,17 @@ sh--vars-before-point
> ;; (defun sh--var-completion-table (string pred action)
> ;; (complete-with-action action (sh--vars-before-point) string pred))
>
> -(defun sh--cmd-completion-table (string pred action)
> - (let ((cmds
> - (append (when (fboundp 'imenu--make-index-alist)
> - (mapcar #'car
> - (condition-case nil
> - (imenu--make-index-alist)
> - (imenu-unavailable nil))))
> - (mapcar (lambda (v) (concat v "="))
> - (sh--vars-before-point))
> - (locate-file-completion-table
> - exec-path exec-suffixes string pred t)
> - sh--completion-keywords)))
> - (complete-with-action action cmds string pred)))
> +(defun sh--cmd-completion-table-gen (string)
> + (append (when (fboundp 'imenu--make-index-alist)
> + (mapcar #'car
> + (condition-case nil
> + (imenu--make-index-alist)
> + (imenu-unavailable nil))))
> + (mapcar (lambda (v) (concat v "="))
> + (sh--vars-before-point))
> + (locate-file-completion-table
> + exec-path exec-suffixes string nil t)
> + sh--completion-keywords))
>
> (defun sh-completion-at-point-function ()
> (save-excursion
> @@ -1713,7 +1711,7 @@ sh-completion-at-point-function
> (list start end (sh--vars-before-point)
> :company-kind (lambda (_) 'variable)))
> ((sh-smie--keyword-p)
> - (list start end #'sh--cmd-completion-table
> + (list start end (completion-table-with-cache #'sh--cmd-completion-table-gen)
> :company-kind
> (lambda (s)
> (cond
> --
> 2.38.1
>
>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-12-01 15:46 ` Eli Zaretskii
@ 2022-12-01 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 13:45 ` Eli Zaretskii
2022-12-02 17:01 ` Yikai Zhao
0 siblings, 2 replies; 7+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-01 20:30 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: yikai, 59678
>> I found that the auto-completion on .sh files (with company-mode) was
>> pretty slow (takes several seconds). It turns out that company-mode
>> would call the capf function with 'metadata action for each
>> candidate, where each function call would need to list all the
>> cmds. In this patch, I modified the code to use
>> completion-table-with-cache which fixes the problem for me.
>
> Stefan, any comments?
Looks OK to me. The description of the problem looks concerning, tho:
if Company really calls the completion table with `metadata` once per
candidate, then there's a bug in company.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-11-29 14:30 bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance yikai
2022-12-01 15:46 ` Eli Zaretskii
@ 2022-12-02 13:44 ` Eli Zaretskii
2022-12-02 17:00 ` Yikai Zhao
1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2022-12-02 13:44 UTC (permalink / raw)
To: yikai, Stefan Monnier; +Cc: 59678-done
> Cc: Yikai Zhao <yikai@z1k.dev>
> From: yikai@z1k.dev
> Date: Tue, 29 Nov 2022 22:30:14 +0800
>
> Hi,
>
> I found that the auto-completion on .sh files (with company-mode) was pretty slow (takes several seconds).
> It turns out that company-mode would call the capf function with 'metadata action for each candidate,
> where each function call would need to list all the cmds. In this patch, I modified the code to use
> completion-table-with-cache which fixes the problem for me.
Thanks, installed on the emacs-29 branch.
In the future, please accompany your changes with ChangeLog-style commit of
messages (see CONTRIBUTE for the details).
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-12-01 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-12-02 13:45 ` Eli Zaretskii
2022-12-02 17:01 ` Yikai Zhao
1 sibling, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2022-12-02 13:45 UTC (permalink / raw)
To: Stefan Monnier; +Cc: yikai, 59678
> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: yikai@z1k.dev, 59678@debbugs.gnu.org
> Date: Thu, 01 Dec 2022 15:30:04 -0500
>
> >> I found that the auto-completion on .sh files (with company-mode) was
> >> pretty slow (takes several seconds). It turns out that company-mode
> >> would call the capf function with 'metadata action for each
> >> candidate, where each function call would need to list all the
> >> cmds. In this patch, I modified the code to use
> >> completion-table-with-cache which fixes the problem for me.
> >
> > Stefan, any comments?
>
> Looks OK to me. The description of the problem looks concerning, tho:
> if Company really calls the completion table with `metadata` once per
> candidate, then there's a bug in company.
Thanks, I therefore installed the changes.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-12-02 13:44 ` Eli Zaretskii
@ 2022-12-02 17:00 ` Yikai Zhao
0 siblings, 0 replies; 7+ messages in thread
From: Yikai Zhao @ 2022-12-02 17:00 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Stefan Monnier, 59678-done
On Fri, Dec 2, 2022 at 9:44 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Cc: Yikai Zhao <yikai@z1k.dev>
> > From: yikai@z1k.dev
> > Date: Tue, 29 Nov 2022 22:30:14 +0800
> >
> > Hi,
> >
> > I found that the auto-completion on .sh files (with company-mode) was pretty slow (takes several seconds).
> > It turns out that company-mode would call the capf function with 'metadata action for each candidate,
> > where each function call would need to list all the cmds. In this patch, I modified the code to use
> > completion-table-with-cache which fixes the problem for me.
>
> Thanks, installed on the emacs-29 branch.
>
> In the future, please accompany your changes with ChangeLog-style commit of
> messages (see CONTRIBUTE for the details).
Thanks. I will do that next time.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance
2022-12-01 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 13:45 ` Eli Zaretskii
@ 2022-12-02 17:01 ` Yikai Zhao
1 sibling, 0 replies; 7+ messages in thread
From: Yikai Zhao @ 2022-12-02 17:01 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Eli Zaretskii, 59678
On Fri, Dec 2, 2022 at 4:30 AM Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
> >> I found that the auto-completion on .sh files (with company-mode) was
> >> pretty slow (takes several seconds). It turns out that company-mode
> >> would call the capf function with 'metadata action for each
> >> candidate, where each function call would need to list all the
> >> cmds. In this patch, I modified the code to use
> >> completion-table-with-cache which fixes the problem for me.
> >
> > Stefan, any comments?
>
> Looks OK to me. The description of the problem looks concerning, tho:
> if Company really calls the completion table with `metadata` once per
> candidate, then there's a bug in company.
Thanks!
I again confirmed that this is the current behavior.
I created an issue for company-mode to follow up.
https://github.com/company-mode/company-mode/issues/1351
>
>
> Stefan
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-12-02 17:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-29 14:30 bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance yikai
2022-12-01 15:46 ` Eli Zaretskii
2022-12-01 20:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 13:45 ` Eli Zaretskii
2022-12-02 17:01 ` Yikai Zhao
2022-12-02 13:44 ` Eli Zaretskii
2022-12-02 17:00 ` Yikai Zhao
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.