From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: A faster derived-mode-p Date: Sun, 14 Feb 2021 18:51:04 -0500 Message-ID: References: <87k0ra9z7w.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4505"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Feb 15 00:52:01 2021 Return-path: Envelope-to: ged-emacs-devel@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 1lBRBI-00012k-Oc for ged-emacs-devel@m.gmane-mx.org; Mon, 15 Feb 2021 00:52:00 +0100 Original-Received: from localhost ([::1]:43446 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lBRBH-0006Mk-Nd for ged-emacs-devel@m.gmane-mx.org; Sun, 14 Feb 2021 18:51:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBRAV-0005un-NQ for emacs-devel@gnu.org; Sun, 14 Feb 2021 18:51:11 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33232) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lBRAS-00072f-JH for emacs-devel@gnu.org; Sun, 14 Feb 2021 18:51:10 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6E863440F4C; Sun, 14 Feb 2021 18:51:07 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 0F22C440F3E; Sun, 14 Feb 2021 18:51:06 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1613346666; bh=OITU1//MnFlnjRtOd8yPMCQ6bTMJWdUWPoj3oHIFtpk=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=N9aazlz6rK8cp+iGJHRFUpNd5HQ6s9ZNfW2OxWiHr4q3Eq43O4MQtK4JaPNOAFumz 1k8CHBiMZrMyHZ60vPDigRYYU/uwxGIT/HXpfdYheIXE/aH51Z+K76J1Mjc2vSui0S 8Rtmnlp0RKtc/OXtpK+E4icJEwCSCD+avd23nBdzlAHvKkRlZ4vxgQA8M5R3MSDlWF unKNQfQ2oQog+UAOgX1JBMPSUN3zQgUmMloTVHtmajCV00a3+5KrgGXD23JWrsw6BQ bm33+r2UQ+AxUQzKjohj4B8YGqbtrrYZE+8gvRmcrIJJVyxtN7kbOL8ILbo+TRWFa1 hCTBHT9K6VDGg== Original-Received: from alfajor (unknown [216.154.41.47]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C8B6612031C; Sun, 14 Feb 2021 18:51:05 -0500 (EST) In-Reply-To: <87k0ra9z7w.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sun, 14 Feb 2021 21:22:11 +0100") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:264813 Archived-At: > There are only 11K commands in the Emacs tree, so I don't know whether > the current default completion predicate is going to turn out to be > problematically slow or not. Here's my suggestion: Instead of trying to speed up those 10K predicates we're going to have to evaluate, we could try to take advantage of the fact that there should be a lot of redundancy there. So we could do something like: (let ((cmds (make-hash-table :test #'equal))) (mapatom (lambda (sym) (when (commandp sym) (push sym (gethash (command-predicate sym) cmds))))) (let (active-cmds) (maphash (lambda (pred syms) (when (funcall pred) (cl-callf nconc active-cmds syms))) cmds) active-cmds)) The only problem I can foresee here is that we have no guarantee that (equal (lambda () (derived-mode-p 'foo-mode)) (lambda () (derived-mode-p 'foo-mode))) To reduce the risk of such problems we could change the "predicate" from being a function that takes 0 arguments, to being a list a list (FUN . ARGS), so instead of (funcall pred) we'd have to do: (apply pred) So instead of (lambda () (derived-mode-p 'foo-mode)) the internal representation of the "predicate" would be (derived-mode-p foo-mode) it should also make equality testing (within `gethash`) faster. Of course, if we can arrange for the command predicates to be written (in the source file) a single time for groups of commands (which would also be beneficial to reduce the amount of redundancy in the source code and the amount of work needed by authors), then we could even use `eq` comparisons and still get most of the benefit. Stefan