From: ludo@gnu.org (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: fmatch
Date: Fri, 07 May 2010 22:23:29 +0200 [thread overview]
Message-ID: <8739y3lav2.fsf@gnu.org> (raw)
In-Reply-To: 201005071624.03781.stefan.tampe@spray.se
Hello!
stefan <stefan.tampe@spray.se> writes:
>> > large patterns yield a speedup of 15 times acording to my tests compared
>> > with (ice-9 match).
>> >
>> > I used guile-1.9.10. Does this release have a lot of checks compiled in
>> > so that the comparison is unfair?
>>
>> All list/pair accessors type-check their arguments (this has always been
>> the case with Guile so that Scheme code cannot yield to segfaults and
>> the like.)
>
> usually the generated match code is somehting like
> (if (pair? x)
> (if (equal? x data)
> (let a34 (cdr x) ...)
> (goto-next))
> (goto-next))
>
> And the checks are already there. So for this isolated system in should
> be fine to skip the check. But I don't think it explains the speed
> difference.
Agreed.
> The core of the matcher is a loop with a set of if's arranged so that in the
> mean it will do 2-3 checks and then find the instruction, so no named labels.
You mean no “labels as values” (info "(gcc) Labels as Values"), right?
> the core of the code look like,
> #define M_CONTINUE {pat ++; continue;}
> while(1)
> {
> //printf("match-instruction (*)> %d\n",((int) Ix) >> 2);fflush(stdout);
> if(SCM_UNLIKELY(Ix == i_cons))
> {
> if(SCM_CONSP(x))
> {
> PUSH(SCM_CDR(x));
> x = SCM_CAR(x);
> M_CONTINUE;
> }
> goto return_false;
> }
Hmmmm. My first reaction is that I’d rather avoid complex VM
instructions like this and instead focus on native compilation (AOT or
JIT) when we feel like improving performance.
What do you think?
[...]
> I also have similar code for usage in prolog like matching e.g. unfication +
> backtracking I would expect at least the same speedup here. Note that for
> this application a pure unwinding of the logic, similar to the match macro
> will yield very bloated code and going for a targeted virtual machine will
> make
> for lean and efficient code.
>
> I hope that in the end a prolog implementation using this approach would be
> 3-4
> times slower that what you have with a more targeted platform like gnu prolog.
This all sounds like exciting work!
> So in a sense this is a test of what you want. Compare the speed difference of
> using c-based or scheme based solution. Still I expect the macth construct to
> be easier to hack and improve uppon and at some point a direct match version
> will win because you can compile it naitively.
Well, until 1.8, the focus in Guile had been to write the “hot spots” in
C, for performance. However, that doesn’t scale well and leads to a
hard to maintain code base (we want to write Scheme in the first place,
not C).
For 2.2 and beyond, I really think the focus should be on allowing hot
spots to be written in Scheme, which means compiling Scheme code
natively. This would be beneficial to all Scheme code, not just this
specific pattern matching construct.
Thanks,
Ludo’.
next prev parent reply other threads:[~2010-05-07 20:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-06 20:39 fmatch stefan
2010-05-07 11:59 ` fmatch Ludovic Courtès
2010-05-07 14:24 ` fmatch stefan
2010-05-07 20:23 ` Ludovic Courtès [this message]
2010-05-07 20:53 ` fmatch stefan
2010-05-09 20:57 ` fmatch Ludovic Courtès
2010-05-09 20:52 ` fmatch stefan
2010-05-10 8:26 ` fmatch Ludovic Courtès
2010-05-11 14:26 ` fmatch Stefan
2010-05-17 20:08 ` fmatch stefan
2010-05-22 21:03 ` fmatch Ludovic Courtès
2010-05-22 21:31 ` fmatch stefan
2010-05-23 16:06 ` fmatch Ludovic Courtès
2010-05-23 15:47 ` fmatch stefan
2010-05-24 20:08 ` fmatch Ludovic Courtès
2010-05-24 21:05 ` fmatch stefan
2010-05-25 17:41 ` fmatch Ludovic Courtès
2010-05-25 21:10 ` fmatch stefan
2010-06-16 21:31 ` fmatch Ludovic Courtès
2010-06-20 19:58 ` fmatch stefan
2010-06-20 21:56 ` fmatch Ludovic Courtès
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=8739y3lav2.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=guile-devel@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).