From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: yikai@z1k.dev Newsgroups: gmane.emacs.bugs Subject: bug#59678: [PATCH] sh-script: use completion-table-with-cache to improve performance Date: Tue, 29 Nov 2022 22:30:14 +0800 Message-ID: <20221129143013.191469-1-yikai@z1k.dev> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11246"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yikai Zhao To: 59678@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 29 15:31:23 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 1p01dq-0002nY-Rm for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 29 Nov 2022 15:31:23 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p01dh-0004vH-Vv; Tue, 29 Nov 2022 09:31:14 -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 1p01dX-0004ru-3s for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2022 09:31:10 -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 1p01dW-000833-JR for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2022 09:31:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p01dW-00036O-DZ for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2022 09:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: yikai@z1k.dev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 29 Nov 2022 14:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59678 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166973223411915 (code B ref -1); Tue, 29 Nov 2022 14:31:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Nov 2022 14:30:34 +0000 Original-Received: from localhost ([127.0.0.1]:54562 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p01d3-000367-GV for submit@debbugs.gnu.org; Tue, 29 Nov 2022 09:30:33 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:37778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p01cz-00035z-QA for submit@debbugs.gnu.org; Tue, 29 Nov 2022 09:30:32 -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 1p01cz-0004GF-8r for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2022 09:30:29 -0500 Original-Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p01cv-0007xO-1t for bug-gnu-emacs@gnu.org; Tue, 29 Nov 2022 09:30:27 -0500 Original-Received: by mail-pj1-x102f.google.com with SMTP id w15-20020a17090a380f00b0021873113cb4so13638344pjb.0 for ; Tue, 29 Nov 2022 06:30:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=blahgeek.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=1XmWPncCZR7f7RF6Nl4jDMVacVp/7n8MhqzLsDbP3qo=; b=W+DLTBK/F5potcL4G5T/vuUDkdcXv+eitxmmgA6Y4cLIPc86KcODVkD/ossgfuKxdb fG5k1tfdfJn/wIeCB7f39O4tN3R2g4VP/4oKjo6zx/inQ5in/ukfWKnQZ6NDs7yGhLqw MyzJN5ZUoUATHNSKcuuOIFf92bCu/MBMIxeqGBYFtC5U5Pqk4YdO68hRjhpXpJGr2Ru/ L+riduG0WqwPxRF/9jJre3nXUXtM+aYj9SUL2QlGHyZl/PyKlDUjiCTJRsGew43WySeN n4tCCdgJZUBh5aTX/jwby+sfVfNFRF8kHKYED0ihb0U5cwwI+YDx8WXWSf5tkk6na7X3 ke8Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=z1k.dev; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=1XmWPncCZR7f7RF6Nl4jDMVacVp/7n8MhqzLsDbP3qo=; b=bZjLxSH4oniqBpM6U/7lSTOLeSbDEVeTqrVN4l9XEOYrvWJiQsojFdLDqRS+vUDIML vS9Losn3oVNcpk3hN6A/ZCHiyfKXeavbwrE7UznK2txL8xm/XklrJ7MDqxgignlfS25Q 87MjYJ4C/F8oyX421ioQN9bW6wRGdyWZvf6YZ8mwVeLLyDpopcyqd8b7r0j2AXrZDyTO TNIu2gkcVGcWm4vjESEueMIyCmjItfV/JFPEnna5xQ7NoXN0KaoEGOx0l4ZQxQDFkfjn kWDRL/inS+e1+XmTOxKflrNhprLnQEpfdO7YqqnVE5eVdk7aMACxMhQ+zxvK4cnetkw0 Ag7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1XmWPncCZR7f7RF6Nl4jDMVacVp/7n8MhqzLsDbP3qo=; b=7CRNuo+/Y/xJJvP1DlRyzq7A1F4dJkfkZzB8Vv+AkKn5j8hkCs19wFG8EcXs9S7myM IM38sMoF0/rfIpamet6t6B3AFzwJCxCFQE5rFtsXvHyuyR8drVS2Qj4xpC0LaFFonGPr EVpkEV5XyoYKW5UJqC+qSnZYIYt82VlphZ6b1zUj4qZQag1ZhRU9e2bhMgr6kPvSTeiP 0HNKlLZXaD9ud4IZPZAl1jhR6clOAoZi+afA6PvBgn7rC59xdFiM1mi/cKEnE8yCfmP/ bTz9/GfX80CL+Xx7Rm57o8az9a8K11/kHHcSo3tU7/GqCrBZOS646nuGdQSgbRLjgu5P myCg== X-Gm-Message-State: ANoB5pl0Oj9DyfVIYHctoKm1kQgACPESbRSyt+gyvjbV4eD57I8t1ogk aCKRhKmlC5BqEpmy/QPzSP+sA6vDNa8lyxZnT2c= X-Google-Smtp-Source: AA0mqf6wWAdrMx10PKOw6SpTuLudG1SF8SE9i5MPkFRIudPHANmoVbHUNpPWEKHw9zYItec5s+LyhQ== X-Received: by 2002:a17:90b:394c:b0:213:1935:9744 with SMTP id oe12-20020a17090b394c00b0021319359744mr60432571pjb.207.1669732221916; Tue, 29 Nov 2022 06:30:21 -0800 (PST) Original-Received: from localhost ([2a0e:b107:178c:3000::23]) by smtp.gmail.com with ESMTPSA id d4-20020a17090a498400b00212daa68b7csm1423152pjh.44.2022.11.29.06.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 06:30:21 -0800 (PST) X-Google-Original-From: oldtown-blahgeek@blahgeek.com X-Mailer: git-send-email 2.38.1 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=i@blahgeek.com; helo=mail-pj1-x102f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:249404 Archived-At: 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