From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Daniel Mendler via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: Add a function for building sort predicates Date: Thu, 01 Feb 2024 21:19:25 +0100 Message-ID: <875xz89bua.fsf@daniel-mendler.de> References: <87msskw1u8.fsf@web.de> <87eddw9k5o.fsf@daniel-mendler.de> <871q9wvz5p.fsf@web.de> <87bk909h7c.fsf@daniel-mendler.de> <87eddwuh0m.fsf@web.de> Reply-To: Daniel Mendler Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9405"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Michael Heerdegen via "Emacs development discussions." To: Michael Heerdegen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Feb 01 21:20:24 2024 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 1rVdXr-0002Da-QX for ged-emacs-devel@m.gmane-mx.org; Thu, 01 Feb 2024 21:20:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rVdX3-00026F-Ku; Thu, 01 Feb 2024 15:19:33 -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 1rVdX1-000261-91 for emacs-devel@gnu.org; Thu, 01 Feb 2024 15:19:31 -0500 Original-Received: from server.qxqx.de ([2a01:4f8:c012:9177::1] helo=mail.qxqx.de) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rVdWz-0001k2-BA for emacs-devel@gnu.org; Thu, 01 Feb 2024 15:19:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=daniel-mendler.de; s=key; h=Content-Type:MIME-Version:Message-ID:Date: References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UC28YxcE7fRpv9LGHDL/Ggs2pHy+eZcAy77wSLunI44=; b=jz1ST/7d42/xopnSy2atpdfQtO KFlYvSxhGosG1izdURVbLl9NDU9OLorszu4OI4qzyZVfFEe5ALIkKK0XTn/9P5EUH9BNYzjSMj9WD knBdaf1LJzt4hl/o1UaksAoVB9NXm5TEZI3BV5ZK70/L6jv/OUiP+ulzvXyjfsOesC1U=; In-Reply-To: <87eddwuh0m.fsf@web.de> (Michael Heerdegen's message of "Thu, 01 Feb 2024 20:22:01 +0100") Received-SPF: pass client-ip=2a01:4f8:c012:9177::1; envelope-from=mail@daniel-mendler.de; helo=mail.qxqx.de 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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:315718 Archived-At: Michael Heerdegen writes: > Daniel Mendler writes: > >> Did you perform some measurements, comparing with the hand-written >> predicate in package.el? The code does not look efficient with the >> function calls and the throws. > > My version was around 6% slower. Using dynamic lookup of the key order. > I did not try with native compiling. Would be interesting to see the results with native compilation. I will try it when I find time. >> In contrast, if the macro creates a sequence of conditions the native >> compiler can optimize the result. It all depends on the use case. If >> the rules are supposed to be customizable and the lists are short, the >> dynamic approach will likely work well enough. For long lists an >> efficient sort predicate makes a difference in my experience, e.g., in >> a dynamically updating completion UI with thousands of candidates, >> since the predicate is called very often. > > A disadvantage is that custom option will have to introduce new :set > dependencies, I wanted to avoid that. What do you mean by :set dependencies? If we use a macro, customization is not possible anymore. So if customization of the rules is a requirement, then we have to go with a function. Another optimization option is to transparently compile to byte code. Iirc such an approach was discussed for `buffer-match-p'. > But in some cases the speed difference might be worth such an > optimization. If you want to experiment, please be my guest. Yes. The question is where this predicate builder is supposed to be used. Probably interfaces like list-packages or generally tabulated-list buffers would not profit so much from optimization. With ELPA and MELPA the packages buffer has around 6000 entries. Daniel