unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludovic.courtes@laas.fr (Ludovic Courtès)
To: guile-devel@gnu.org
Subject: Re: Evolution & optimization of the module system
Date: Thu, 22 Feb 2007 10:20:55 +0100	[thread overview]
Message-ID: <87lkiq8s5k.fsf@laas.fr> (raw)
In-Reply-To: <87wt2bxibp.fsf@zip.com.au> (Kevin Ryde's message of "Thu, 22 Feb 2007 09:21:46 +1100")

Hi,

Kevin Ryde <user42@zip.com.au> writes:

> ludovic.courtes@laas.fr (Ludovic Courtès) writes:
>>
>> Actually, `process-duplicates' is O(N*USES) _for each module used_.  So
>> the overall duplicate processing is really O(N*USES^2).  With the
>> patched version, the whole process is O(N*USES).  That can make quite a
>> difference when USES > 1.
>
> It should be ok, it's only hash table lookups, which are fast.  And N
> is normally pretty modest too.

I don't think so.  Remember: `module-import-interface' (used by
`process-duplicates'), in the current Guile, is _not_ a hash table
lookup, it's a traversal of the module's use list.  The patched version
is always USES times as fast as the current implementation.  So even
with USES <= 5, it does make a difference.

The measurements in the `module-duplicates.scm' file I posted choose
USES = 10000 by default, which is arguably unrealistic.  However,
timings are way too small when choosing USES < 1000.

> Copying the table of 2000 core bindings into every module doesn't
> sound good, not if it's only for once-off duplicates checking.

I agree that it sounds a bit overkill at first sight.  ;-)  However, it
benefits to both duplicate checking and variable lookup.

> If you
> want you can check the existing innermost loops are good.  In
> process-duplicates var1 and var2 are almost always different (one of
> them #f usually), so getting that down to C with some sort of
> "hashq-intersection" or "hashq-for-each-intersection" would help a
> lot.  I'd predict throwing a little C at bottlenecks like that will be
> enough.

Yes, that would probably help a little.  However, I was trying to have
an algorithmic approach to the issue, being convinced that the most
important gains can be obtained this way.  So I'd like to stick to an
algorithmic evaluation for now and only then consider
"micro-optimizations".

> Another possibility would be to defer duplicates checking until the
> end of a define-module or use-modules form (or even until the end of
> the file), if mutual cross-checks can be done faster en-block, if you
> know what I mean.

That's already what happens: When `process-define-module' finishes, it
invokes `module-use-interfaces!', passing it all the imported modules.
If a `use-modules' form is used later in the source file, the a new
duplicate processing stage occurs.  Currently, it doesn't make any
difference performance-wise, though, since `process-duplicates' only
handles one imported module at a time (and I can't think of any other
way to do it).

> It could use a temporary combined hash if that
> helped (perhaps sharing bucket cells to save gc work).

What do you mean by "combined hash"?

> The particular
> "module-define!" you struck should obviously be only about USES many
> hash lookups (ie. about a dozen typically), most of the time, if
> that's not already the case.

Theoretically, yes.  However, that can only be the case if observers are
passed precise information about what changed in the observed module,
such a description of the operation that led to the change (e.g.,
`define') and a list of affected bindings.  Currently, observers are
just notified that "something" changed, thus they have to run
`process-duplicates' in its entirety.

Anyway, I'm not sure we should worry too much about "`module-define!' at
run-time".

> They're special in that we know there's no clashes between them.
> process-duplicates should ignore any ice-9 vs ice-9, if that doesn't
> happen already.

I'd prefer to first optimize the general case, and then only resort to
such special-casing optimizations when all other recipes failed.
Special-casing makes code more complex and harder to work with IMO.

Thanks,
Ludovic.


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


  reply	other threads:[~2007-02-22  9:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-17 15:15 Evolution & optimization of the module system Ludovic Courtès
2007-02-18 23:32 ` Kevin Ryde
2007-02-19  9:24   ` Ludovic Courtès
2007-02-21 22:21     ` Kevin Ryde
2007-02-22  9:20       ` Ludovic Courtès [this message]
2007-02-22 22:23         ` Kevin Ryde
2007-02-23 13:15           ` Ludovic Courtès
2007-02-25 23:37             ` Kevin Ryde
2007-02-26 21:15               ` Ludovic Courtès
2007-02-26 22:46                 ` Kevin Ryde
2007-02-27  8:21                   ` Ludovic Courtès
2007-04-08 23:06               ` Ludovic Courtès
2007-04-08 23:25                 ` Ludovic Courtès
2007-04-08 23:24               ` Ludovic Courtès
2007-04-30  8:39                 ` Ludovic Courtès
2007-05-05 20:48                   ` Ludovic Courtès
2010-07-20 21:20                     ` Andy Wingo
2010-07-20 22:24                       ` 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=87lkiq8s5k.fsf@laas.fr \
    --to=ludovic.courtes@laas.fr \
    --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).