unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Learning to write interpreted code
@ 2007-08-09 14:49 Ludovic Courtès
  2007-08-09 15:07 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Ludovic Courtès @ 2007-08-09 14:49 UTC (permalink / raw)
  To: guile-devel

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Learning to write interpreted code
  2007-08-09 14:49 Learning to write interpreted code Ludovic Courtès
@ 2007-08-09 15:07 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2007-08-09 15:07 UTC (permalink / raw)
  To: guile-devel

ludo@gnu.org (Ludovic Courtès) writes:

> 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!

Actually, `statprof' is magnifying the effect on total run time since I
can hardly notice a 10% difference when running the thing without
statprof...

Sorry for the noise.

Ludovic.




_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-devel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-08-09 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-09 14:49 Learning to write interpreted code Ludovic Courtès
2007-08-09 15:07 ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).