GNU bug report logs - #12033
format should be faster

Previous Next

Package: guile;

Reported by: nalaginrut <nalaginrut <at> gmail.com>

Date: Mon, 23 Jul 2012 13:55:02 UTC

Severity: normal

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


Message #31 received at 12033 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Noah Lavine <noah.b.lavine <at> gmail.com>
Cc: 12033 <at> debbugs.gnu.org, nalaginrut <nalaginrut <at> gmail.com>
Subject: Re: bug#12033: closed (Re: bug#12033: format should be faster)
Date: Tue, 21 Aug 2012 13:37:29 +0200
Hi,

Noah Lavine <noah.b.lavine <at> gmail.com> skribis:

>> --------------------code-------------------
>> scheme@(guile-user)> ,profile (let lp ((i 10000)) (if (> i 0) (begin
>> (format #f "0x~2'0x, 0x~2'0x, 0x~2'0x" i i i) (lp (1- i)))))
>> %     cumulative   self
>> time   seconds     seconds      name
>> 22.58      0.56      0.23  tilde-dispatch
>> 12.90      1.00      0.13  format
>> 12.90      0.13      0.13  number->string
>>   8.06      0.13      0.08  format:out-char
>>   4.84      0.80      0.05  format:format-work
>> --------------------end-------------------
>>
>> In this case, we tried "0x~2'0x" and it's so slow that we can't bare it.
>> i=10000 is fast, but we need (* 600 80000)
>> And we found that "tilde-dispatch" cost too much. Is there any possible
>> to optimize it?
>
> It seems clear that in this case, Guile "should" know how to dispatch
> on the format string just once, outside of the loop, instead of doing
> it in every iteration.

I think Andy would say: “inline cache!”.  :-)

> What do people think of declaring format as a macro?

That’s tempting, but it breaks the ABI (so not for 2.0), and it breaks
for users who do ((@ (ice-9 format) format) #t "foo"), for instance.

Maybe we could have a ‘format*’ macro that does as much as possible of
the dispatch at compile-time?  The difficulty would be to factorize
dispatch code with the ‘format’ procedure.

Another (IMO less elegant) option would be to have an optional compiler
optimization pass that would do something similar.

Thanks,
Ludo’.




This bug report was last modified 12 years and 357 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.