unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: Re: string-for-each vs. for-each+string->list performance
Date: Sat, 6 Jun 2020 23:33:38 -0700	[thread overview]
Message-ID: <CA+XASoUk6z3-_i2O_8zqGf7fmQum_pT12RaQaXVxDU8jRN3Uxw@mail.gmail.com> (raw)
In-Reply-To: <CA+XASoWOno30sV8A3sz1n8w2TNkB+gjikgmXWk+c_2BDJ8iH0A@mail.gmail.com>

On Sat, Jun 6, 2020 at 11:27 PM Aleix Conchillo Flaqué <aconchillo@gmail.com>
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.
>
>
Forgot to mention that Chritopher also pointed out that string->list has an
optimization for narrow strings:

http://git.savannah.gnu.org/cgit/guile.git/tree/libguile/srfi-13.c#n294

which means it doesn't use string_ref where the scheme code has to do it.
So, it might be due to this?

Aleix


  reply	other threads:[~2020-06-07  6:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-07  6:27 string-for-each vs. for-each+string->list performance Aleix Conchillo Flaqué
2020-06-07  6:33 ` Aleix Conchillo Flaqué [this message]
2020-06-07 11:20 ` Linus Björnstam
2020-06-07 13:50 ` Linus Björnstam
2020-06-12 20:13   ` Ludovic Courtès
2020-06-13  6:41     ` Linus Björnstam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+XASoUk6z3-_i2O_8zqGf7fmQum_pT12RaQaXVxDU8jRN3Uxw@mail.gmail.com \
    --to=aconchillo@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).