[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string-for-each vs. for-each+string->list performance
From: |
Linus Björnstam |
Subject: |
Re: string-for-each vs. for-each+string->list performance |
Date: |
Sun, 07 Jun 2020 13:20:33 +0200 |
User-agent: |
Cyrus-JMAP/3.3.0-dev0-519-g0f677ba-fm-20200601.001-g0f677ba6 |
Try disassembling it. I suspect the for-each is inlined, and that whatever is
going on involves instruction explosion which means you get a lot more
optimization opportunities.
That difference seems large though. Try it in guile 2.2 (which shouldnt have
the same opportunities for optimization).
--
Linus Björnstam
On Sun, 7 Jun 2020, at 08:27, Aleix Conchillo Flaqué wrote:
> Hi,
>
> in the latest guile-json, 4.1.0. I changed some code to use
> for-each+string->list. The performance seemed nice and I released it.
>
> Christopher Lam pointed out that I could have used string-for-each instead.
> I made the change but the performance degraded a lot:
>
> string-for-each:
>
> scheme@(json parser)> ,t (->bool (scm->json-string json))
> $19 = #t
> ;; 17.909537s real time, 18.063382s run time. 0.207281s spent in GC.
>
> vs
>
> for-each + string->list:
>
> scheme@(json parser)> ,t (->bool (scm->json-string json))
> $20 = #t
> ;; 2.998381s real time, 3.319349s run time. 0.471969s spent in GC.
>
> string-for-each is implemented in scheme here, if Im not wrong:
>
> http://git.savannah.gnu.org/cgit/guile.git/tree/module/rnrs/base.scm#n89
>
> string->list and for-each would use C.
>
> Is that huge gap expected?
>
> This is with Guile 3.0.2.
>
> Best,
>
> Aleix
>