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: named-let Date: Wed, 20 Jan 2021 14:44:56 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31052"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Jan 20 20:46:34 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 1l2JR4-0007zO-6d for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jan 2021 20:46:34 +0100 Original-Received: from localhost ([::1]:43906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l2JR3-0006gg-9s for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Jan 2021 14:46:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2JPb-0005t9-FP for emacs-devel@gnu.org; Wed, 20 Jan 2021 14:45:03 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:1716) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l2JPY-000088-RH for emacs-devel@gnu.org; Wed, 20 Jan 2021 14:45:02 -0500 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 0FE7444080E; Wed, 20 Jan 2021 14:44:59 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id BD2E244033C; Wed, 20 Jan 2021 14:44:57 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1611171897; bh=5DxN1QRqjVYO+RSuJtVAkkVTegRf7r8GIUfmo6RY4BM=; h=From:To:Subject:References:Date:In-Reply-To:From; b=QVSMMZHoW9TosM9v0g6soSh+Vr7gCvK61t2+l9cLyZfo37UaIW3dfb+TJ/EoEL1W0 f6Vrxv5qpZc3y8ZeARXBMWl++LjFQ9l0+lXWnvPQacorRewPgSgzGNDN0iuv6FRM9G o07kNzRpyUMN6TRahKKhq9jB/ux4zszf8nANtzkDGQHcoVgcCwB3FMKG/NKz44Ufw6 u7gjmJAvlXHWMsHLhqfdc+SNki10xrHrAj4QOdRNdQGYtPGPjptFpbWImQtQpk9pOF ZfUdXW1hBzcwSiKzo8kR8vwAP5KGTLq/GK330aih3Z4y1z3FNGmCyY5LKB9rQT3wFP ZjPSyUni02M5g== Original-Received: from alfajor (unknown [45.72.224.181]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 6E4B51204A7; Wed, 20 Jan 2021 14:44:57 -0500 (EST) In-Reply-To: (Stefan Monnier's message of "Fri, 08 Jan 2021 20:43:13 -0500") 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:263219 Archived-At: > The recent discussion around loops motivated me to look a bit further > into named-let. It's actually easy to define: I now added this `named-let` to `subr-x.el`. Along with it, I installed two additional optimizations to the byte-code optimizer. With those optimization, the byte code generated from (defun length-named (xs) (named-let recurse ((xs xs) (l 0)) (if xs (recurse (cdr xs) (1+ l)) l))) is about 33% slower than that generated from: (defun length-fast (xs) (let ((l 0)) (while xs (setq l (1+ l)) (setq xs (cdr xs))) l)) (for reference, without the tail-call optimization, `length-named` was about 300% (i.e. 4x) slower, and with TCO but without the recent extra tweaks, it was about 70% slower; and the native `length` is 15x faster). The remaining 33% seem harder to reach, tho. They're 3 extra instructions: 2 `stack-ref` instructions to copy the two parameters at the beginning of the loop body, and one `discardN` instruction to drop those 2 parameters at the end of the loop body. I guess we can live with those 33% for now: this is a fairly pathological test where the loop's body does particularly little, so the loop overhead is magnified. Stefan