From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Learning to write interpreted code Date: Thu, 09 Aug 2007 16:49:56 +0200 Message-ID: <877io4pxt7.fsf@chbouib.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1186671120 12708 80.91.229.12 (9 Aug 2007 14:52:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 9 Aug 2007 14:52:00 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Aug 09 16:51:55 2007 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IJ9Mh-0001BJ-0O for guile-devel@m.gmane.org; Thu, 09 Aug 2007 16:51:55 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IJ9Mg-0006YX-EP for guile-devel@m.gmane.org; Thu, 09 Aug 2007 10:51:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IJ9Lb-0006BF-J6 for guile-devel@gnu.org; Thu, 09 Aug 2007 10:50:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IJ9Lb-0006B3-1G for guile-devel@gnu.org; Thu, 09 Aug 2007 10:50:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IJ9La-0006Av-PV for guile-devel@gnu.org; Thu, 09 Aug 2007 10:50:46 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IJ9La-00016g-AW for guile-devel@gnu.org; Thu, 09 Aug 2007 10:50:46 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1IJ9LS-0005c4-3L for guile-devel@gnu.org; Thu, 09 Aug 2007 16:50:38 +0200 Original-Received: from adh419.fdn.fr ([80.67.176.9]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Aug 2007 16:50:38 +0200 Original-Received: from ludo by adh419.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 09 Aug 2007 16:50:38 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: adh419.fdn.fr X-URL: http://www.laas.fr/~lcourtes/ X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: i486-pc-linux-gnu User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) Cancel-Lock: sha1:lVhp/q0h/yqULARp+12Kgxf2uGY= X-Detected-Kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:6672 Archived-At: Hi, I've been facing various slowness issues recently, which led me to play with profilers. Today, I profiled Guile-RPC's XDR encoding routine with `statprof' and got this: % cumulative self time seconds seconds name 9.66 12.64 12.64 not 6.57 9.38 8.59 xdr-basic-type-type-pred 6.53 9.44 8.54 xdr-basic-type-size 5.62 8.26 7.36 xdr-basic-type-encoder 5.11 8.93 6.68 xdr-basic-type? 3.69 4.83 4.83 eq? [...] Total time: 130.8 seconds (2147/100 seconds in GC) Twelve seconds are being spent in `not', 5 seconds in `eq?', and 8 seconds in each record accessor (all of which could be implemented in a few machine instructions). So I went ahead and removed the `not' within the loop, rewriting `(if (not c) a b)' to `(if c b a)', and voilą: % cumulative self time seconds seconds name 8.88 1.19 1.08 xdr-basic-type-size 5.14 0.74 0.62 xdr-basic-type-type-pred 4.21 0.68 0.51 xdr-basic-type-encoder 3.74 1.64 0.45 + 3.74 0.45 0.45 eq? [...] Total time: 12.11 seconds (167/100 seconds in GC) An order of magnitude faster! I suppose that, as a side effect, the GC needed to run less often because the evaluator was producing less garbage. Conclusions: 1. When writing code for an interpreter, one has to be prepared for insignificant things taking surprisingly large amounts of time. :-) 2. My inlining patch [0] was not too irrelevant, I suppose. 3. Upon user request, we may also want to allow the memoizer of `if' to automatically rewrite expressions of the form `(if (not c) ...)'. Cheers, Ludo'. [0] http://thread.gmane.org/gmane.lisp.guile.devel/6043 _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel