From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance Date: Thu, 01 Dec 2022 17:46:01 +0200 Message-ID: <83wn7bgm9y.fsf@gnu.org> References: <20221129143013.191469-1-yikai@z1k.dev> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35638"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59678@debbugs.gnu.org To: yikai@z1k.dev, Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 01 16:47:29 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0lmb-00095Q-3G for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 01 Dec 2022 16:47:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0lmG-0001Xe-10; Thu, 01 Dec 2022 10:47:08 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0lmA-0001Ua-LY for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:47:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p0lmA-0006Sp-Ao for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:47:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p0lmA-0000Rk-7W for bug-gnu-emacs@gnu.org; Thu, 01 Dec 2022 10:47:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 01 Dec 2022 15:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59678 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 59678-submit@debbugs.gnu.org id=B59678.16699096021694 (code B ref 59678); Thu, 01 Dec 2022 15:47:02 +0000 Original-Received: (at 59678) by debbugs.gnu.org; 1 Dec 2022 15:46:42 +0000 Original-Received: from localhost ([127.0.0.1]:40409 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0llq-0000RF-B9 for submit@debbugs.gnu.org; Thu, 01 Dec 2022 10:46:42 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50444) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p0llo-0000Qr-3X for 59678@debbugs.gnu.org; Thu, 01 Dec 2022 10:46:40 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0lld-00060g-EA; Thu, 01 Dec 2022 10:46:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=wEve7viSccEqRAMlYprHBe35OxJCYOUMlOInf3unz+w=; b=FR75CSggV311 4dS11ykGLjJqnnODQh2zVFc3afVmmnW9ZXSdOVTGM08ulGsLM2e38FF46Kxr96mhlklw+lg9l8XjE NfO07SQzPSrElpEUO/04M2cK7F69vY8T6+tGQ3o5VrUqirlFj+cA1SAmKJ7ewNvFp/fo1Me31zEtF 60INXAZXxBMZP729MWE7y3qMFz5ZcTLfAL15AuoMLLPwDFFQrul4p6qVVGV6mVOmXLIMc3TOch72k fFwvVfJLd+0+5SZO8zE4jxIXr2EdKuW68j+nxwfgdxU9cIiWT6IVTXtUO5c66qYaEl6PLksVCFibi y+RKxE2sL1UXMO4RLFA+2g==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0llc-00029x-55; Thu, 01 Dec 2022 10:46:28 -0500 In-Reply-To: <20221129143013.191469-1-yikai@z1k.dev> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:249642 Archived-At: > Cc: Yikai Zhao > 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 > > > > >