From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: return Date: Fri, 03 Dec 2010 17:29:55 -0500 Message-ID: References: <87hbeu7l84.fsf@stupidchicken.com> <87bp52ae9g.fsf@catnip.gol.com> <87r5dyfxmn.fsf@stupidchicken.com> <87ei9y5z0v.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1291415427 25532 80.91.229.12 (3 Dec 2010 22:30:27 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 22:30:27 +0000 (UTC) Cc: emacs-devel@gnu.org, Miles Bader To: Chong Yidong Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Dec 03 23:30:22 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POe90-0005nl-IO for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 23:30:22 +0100 Original-Received: from localhost ([127.0.0.1]:52689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POe8z-000628-Uq for ged-emacs-devel@m.gmane.org; Fri, 03 Dec 2010 17:30:22 -0500 Original-Received: from [140.186.70.92] (port=51340 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POe8p-0005yI-UB for emacs-devel@gnu.org; Fri, 03 Dec 2010 17:30:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POe8o-0007dv-Tj for emacs-devel@gnu.org; Fri, 03 Dec 2010 17:30:11 -0500 Original-Received: from pruche.dit.umontreal.ca ([132.204.246.22]:37654) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POe8n-0007dN-AK; Fri, 03 Dec 2010 17:30:09 -0500 Original-Received: from pastel.home (lechon.iro.umontreal.ca [132.204.27.242]) by pruche.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id oB3MTweA028697; Fri, 3 Dec 2010 17:29:58 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id B915BA8364; Fri, 3 Dec 2010 17:29:55 -0500 (EST) In-Reply-To: <87ei9y5z0v.fsf@stupidchicken.com> (Chong Yidong's message of "Fri, 03 Dec 2010 16:26:08 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV3698=0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133365 Archived-At: >> You mean the performance overhead from adding an extra internal_catch? >> I doubt there's a free lunch here; adding a "return" or "return-from" >> mechanism would also add overhead, and that overhead would apply to >> every single funcall. Still, it's a worthwhile experiment to implement >> "return"/"return-from" and see how big the performance impact is. > I did a quick experiment, and turns out built-in blocking is a little > faster than an explicit `catch', mostly because of reduced consing. I > tested with a function that runs 500,000 tight `while' loops: > (defun test-loop-with-catch () > (dotimes (ii 500000) > (let ((ll '(1 2 3 4 5 6 7 8 9 10))) > (catch 'exit > (while ll (setq ll (cdr ll))))))) > The run time is 1.164s, as opposed to 1.084s with the `catch' omitted. > So an explicit `catch' adds about 10 percent to the run time. > If I hack Fwhile to perform a catch internally, the runtime for the test > function (with the `catch' omitted) is 1.057s, within the margin of > error of the unhacked Emacs. A few questions: - how do you explain that Fwhile with internal catch is faster (1.057 < 1.084) than without an internal catch? Or is that what you mean by "within the margin of error"? - You seem to be measuring time for the interpreted code, is that right? If so, I think it would be more interesting to measure the time for byte-code. The little tests I've performed seem to indicate that for interpreted code the extra `catch' doesn't make much of a difference, but for the compiled version of your test, the difference is around 20%. > This (very limited) test indicates that adding built-in support for > block, return, and return-from should have little performance impact. > (Though the block tags ought to use a specialized obarray instead of > what cl-macs.el does, which is to intern them as "--cl-block-%s--".) If we add support for C-like exit statements (break/return, that only work locally and hence don't add any extra run-time cost) to the byte-compiler, that would be nice. Stefan