From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Hongyi Zhao Newsgroups: gmane.emacs.help Subject: Re: Too long completion delay time in LISP interaction mode. Date: Wed, 20 Oct 2021 14:24:58 +0800 Message-ID: References: <87tuhcs2ov.fsf@gnu.org> <87pms0s0ex.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27478"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs To: Tassilo Horn Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 20 08:27:02 2021 Return-path: Envelope-to: geh-help-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 1md542-0006r3-33 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 20 Oct 2021 08:27:02 +0200 Original-Received: from localhost ([::1]:36664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1md540-0006pJ-H3 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 20 Oct 2021 02:27:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1md52G-0006nx-Tz for help-gnu-emacs@gnu.org; Wed, 20 Oct 2021 02:25:13 -0400 Original-Received: from mail-ua1-x929.google.com ([2607:f8b0:4864:20::929]:36862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1md52F-0003FA-3g; Wed, 20 Oct 2021 02:25:12 -0400 Original-Received: by mail-ua1-x929.google.com with SMTP id e10so4637411uab.3; Tue, 19 Oct 2021 23:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=IdJ5qiRAksK7EFxEFwRAAZjN6EyoZ11Sp5iW+DnHIB0=; b=V/M+4hUMYqtV96EweuA/UVeZ6nlBF9xubFDSl3/Rp8DtI/s8UZom6zh78UQYTUoula BJReiC3f+isNHwo96SwgSazUH1MwjkCsjwdIe4ekzV/G9ESlLnn8q7DqLSrGQZb+1EcW 7+KQsWynART01EhuhDOc3OonOmL5Jc6Q0Msd+MGj8ZoRNzcm+4ZlG5yXbCzRnqEMDsoi sRlVPXaXkv8/iF2KT5ZvBLpPrQdtcydNH+OiprNarMh83bzRjtPKQwqzeVYeUA0aHzZ0 ojCSsn5j0EKvjreL+vcLoqhVRsGsLPDRtHzAhjt+pXOa8i7Y3SmquM0sB9QksvhoVJBN qy4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=IdJ5qiRAksK7EFxEFwRAAZjN6EyoZ11Sp5iW+DnHIB0=; b=ZWs2GSJnjeeCY9MtJSCvM7GHSbCBD2IyndNgzmTrnpl23xUU9eOdTa9NspJWTelh3p AfonpQS2S0SM5yxY2VB/GsBbU3gVU2nGaiCEbxG3L35qj+PHYN08V9uNdJbEo4eisJ5g 77jWmJQw2e5RwKQtqs2P8eC84N+Lilccv63+7Piy7mjdOqaC4PuqFUV+1fuXk+Ojbius wecJOT33fM5MRUBCJmYf1yYS+QNxmkn5PJ34TN/hFNQozgyaN6jD8Zj8PRutfw62afec 4P0TX6UeXT+OQfdx0cyL6O1HgZhI8eBYoZlzcfhMJQn70CT5hxwRuRh6N6o5reu4/iMg ABBg== X-Gm-Message-State: AOAM530spI9clJqoiWoaviU05tzSySQnlfqlefVIYReXKXvycaGb2s07 uygOxqi4SOWlcFvIIJiY/M90fy9w6lObWioi8iIEHWxF9JVfiTXm X-Google-Smtp-Source: ABdhPJweDSH6EFFHt3pIC5Ptr8GMyWVwVxxWS77W6ehugsM2yw3pi+qo51XDzqxCZQ9L1Idnb2OZK9/8m9jx3rrT920= X-Received: by 2002:a67:edd7:: with SMTP id e23mr39593736vsp.14.1634711109420; Tue, 19 Oct 2021 23:25:09 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::929; envelope-from=hongyi.zhao@gmail.com; helo=mail-ua1-x929.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, 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: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133907 Archived-At: On Wed, Oct 20, 2021 at 2:11 PM Hongyi Zhao wrote: > > On Wed, Oct 20, 2021 at 1:58 PM Tassilo Horn wrote: > > > > Hongyi Zhao writes: > > > > >> First, I'd try to isolate where the slowdown happens. The > > >> screenshots suggests you are using company-mode with custom hacks to > > >> get the numbering of candidates and you are using some fuzzy > > >> completion-style. > > >> > > >> So I'd start with emacs -Q and typing (map in *scratch* to get > > >> the *Completions* buffer. That will probably be fast but deliver > > >> less results because of the default value of `completion-styles'. > > >> Then I'd try out your settings of `completion-styles' (and > > > > > > `C-h o completion-styles RET' > > > > > > completion-styles is a variable defined in =E2=80=98minibuffer.el=E2= =80=99. > > > > > > Its value is (hotfuzz) > > > > Never heard of it. > > See here: > > https://github.com/axelf4/hotfuzz > > > But is it a suitable catch-all completion style, > > i.e., suitable for using it without another more prefix-oriented style > > preceeding it? FWIW, when I type "(map", I'm most probably not > > interested in having smartparens-mode, or > > lsp:document-symbol-capabilities-hierarchical-document-symbol-support? > > showing up as the top candidates but more in mapcar, mapc, mapcan, you > > name it... > > Agree with you. > > > >> Also, using the profiler might shed some light on where the time is > > >> spent, see (info "(elisp) Profiling"). > > > > > > `M-x profiler-start RET cpu and mem RET' > > > > I think you only need cpu here. > > Thank you for pointing this out. > > > > Typeset (map) in scratch buffer, and then > > > > > > `M-x profiler-report RET', gives the following results: > > > > > > 262,542,852 87% - command-execute > > > 262,542,852 87% - funcall-interactively > > > 262,538,196 87% - counsel-M-x > > > 262,538,196 87% - let > > > 262,355,940 87% - ivy-read > > > 262,355,940 87% - apply > > > 262,354,884 87% + # > > > 182,256 0% + counsel--M-x-externs > > > > So the bottleneck is in the lambda which you didn't expand. > > I disabled hotfuzz now, and the following result is obtained by > profiling the CPU with the same steps as described above: > > 472 88% - command-execute > 472 88% - funcall-interactively > 472 88% - counsel-M-x > 472 88% - let > 448 84% - ivy-read > 448 84% - apply > 444 83% + # > 4 0% + my/company--transform-candidates > 24 4% + counsel--M-x-externs > 45 8% + ... > 15 2% + redisplay_internal (C function) > > > > But I'm also not sure if you are profiling the right thing because I do= n't think > > that in-buffer completion (in terms of `completion-at-point-functions') > > starts with M-x (or counsel-M-x). > > I'm not sure if it's relevant to the following configuration in my > `~/.emacs.d/init.el': > > (use-package counsel > :diminish counsel-mode > :after helpful > :init (setq ivy-use-selectable-prompt t > search-default-mode #'char-fold-to-regexp > counsel-describe-function-function #'helpful-callable > counsel-describe-variable-function #'helpful-variable) > :bind (("M-x" . counsel-M-x) `C-h o counsel-M-x RET' gives the following: counsel-M-x is an interactive Lisp closure in =E2=80=98counsel.el=E2=80=99. It is bound to , M-x. So it is unnecessary to set the above key binding. And the profiling results are as follows without this keybinding: 3056 55% - command-execute 3056 55% - funcall-interactively 1227 22% - counsel-M-x 1227 22% - let 1132 20% - ivy-read 1132 20% - apply 1132 20% + # 95 1% + counsel--M-x-externs 989 18% + next-line 622 11% + counsel-describe-symbol 123 2% + save-buffer 46 0% + recentf-open-most-recent-file-1 30 0% mwheel-scroll 12 0% + swiper 6 0% + kill-whole-line 1 0% # 1357 24% + ... 516 9% + redisplay_internal (C function) 500 9% + timer-event-handler 33 0% + substitute-command-keys > ;; https://github.com/alpha2phi/dotfiles/blob/7c8c2c1ac9cf1cf95d6032= 3f49c19545cfcef555/config/emacs/elisp/completion.el#L21 > ;; ("C-x C-f" . counsel-fzf) > ("C-x C-f" . counsel-find-file) > ;;https://github.com/abo-abo/swiper/issues/2888#issuecomment-8748937= 94 > ("C-x 8 RET" . counsel-unicode-char) > ("" . counsel-bookmark) > ("s-4" . counsel-bookmark) > ("s-r" . counsel-recentf)) > :config (counsel-mode 1) > (defalias 'recent 'counsel-recentf)) > (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history) > > HZ