unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
To: ludo@chbouib.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: Evolution & optimization of the module system
Date: Mon, 19 Feb 2007 10:32:29 +1100	[thread overview]
Message-ID: <877iufhwj6.fsf@zip.com.au> (raw)
In-Reply-To: <87sld4g6io.fsf@chbouib.org> (Ludovic Courtès's message of "Sat, 17 Feb 2007 16:15:11 +0100")

ludo@chbouib.org (Ludovic Courtès) writes:
>
> (1) has to do mainly with `module-use!' vs. `module-use-interfaces!' (as
> was discussed recently).  Namely the fact that duplicate processing is
> not always performed, depending on whether one uses `module-use!' or
> some other means to use a module.

There's nothing broken though is there, it's just a trap for the
unwary (like me for instance, wrestling with use-srfis)?

> There's still more to do to achieve (2) (notably actual documentation
> ;-))

I've put that off, because a lot looks like internals, and I'd
wondered if r6rs might offer some of its own "introspection" stuff.

> The patch solves this issue by making
> duplicate processing inescapable.  Likewise, variable lookup currently
> has two implementations (which have the same behavior, though): the C
> `module_variable ()' and the Scheme `module-variable'.  The patch leaves
> only one implementation of that.

Moving stuff into C is a good thing.  You can propose that separately
if you like, it should be able to go straight in.  (And could be a
candidate for the 1.8 branch if the performance help is noticable.)

> Although duplicates should be the exception rather than the rule[*],
> duplicate processing is pretty costly: the current `process-duplicates'
> is roughly O(N*USES),

USES is supposed to be smallish of course though.

> Likewise,
> variable lookup (e.g., in `module_variable ()') is O(USES).  I believe
> that both may have a sensible impact on startup time.

Something definitely slows down startup over 1.6.  I'd guessed it was
strings, but I failed miserably at making either gprof or
functioncheck give some call counts to prove or disprove that.

> The patch addresses this by changing the data structures used by
> modules: instead of a list of used modules, it uses a second "obarray",
> called the "import obarray", that maps symbols to the modules providing
> them.

That would increase the memory used by a module though, would it?  Big
modules imported into lots of other places would have their binding
list much copied would they?  (I'm thinking for instance of gtk and
gnome, and thinking purely selfishly since I import gtk and/or gdk
into a bunch of my modules.)

> This has several implications.  First, duplicate processing occurs the
> same way for dynamically added bindings than for "statically imported"
> bindings.  Second, it makes load-time-dependent duplicate policies such
> as `last' and `first' irrelevant (since they are inherently
> non-deterministic).

Last and first still sound pretty sensible.

> Third, it makes dynamic addition of bindings relatively costly.

Depends how often that happens I suppose.  There's no actual
documented way to do it is there? :-)  Maybe some tomfoolery with
macros and eval ...

> (2) the
> SMOB classes are added to a separate module called `(oop goops
> smob-classes)'.  Since only `(oop goops)' uses it, it is the only one
> that needs to re-process duplicates as new SMOB classes are added.

Sounds ok in principle.

> From the measurements I've made, the new version is
> around 40 times faster than the other one.

Is that in part due to moving the variable lookup to C?

> So the question is: is the `beautify-user-module!' overhead compensated
> by the variable lookup and duplicate processing gains?

I'd be inclined to say probably not, but that maybe there's another
way.

Duplicates is trying to find the intersection between one set of
symbols (from one module) and some reasonably smallish number N of
other sets (from other modules) is it?  I wonder if there's some way
to find that more efficiently.

I guess the `warn' in the default duplicates handling makes it
necessary to find all the duplicates.  Nice enough feature, but
without it there'd be no need to check any duplicates at all, or only
check against the few `#:replace' lists.

Maybe the worst afflicted programs should be advised to turn it off,
or even turn it off globally when confident there's no accidental
clashes.  And for a start I guess we don't need any duplicates work in
the core, at least up until reaching the `--use-srfi' stage of
startup, if that isn't already the case.


> +      (define %default-import-size
> +        ;; This should be the size of the pre-module obarray.
> +        500)

Which also ends up being a minimum size of course ...

> +/* Copy the given alist, i.e., duplicate all its pairs recursively.  */
> +static inline SCM
> +alist_copy (SCM alist)

If you end up using this you could move scm_srfi1_alist_copy from
srfi/srfi-1.c into the core (leaving behind a #define and a
re-export).

> -/*
> -  TODO: should export this function? --hwn.
> - */
> -static SCM
> -scm_export (SCM module, SCM namelist)
> +SCM
> +scm_module_export (SCM module, SCM namelist)

That could be an "scm_i_" (for now at least) if it's not documented.


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


  reply	other threads:[~2007-02-18 23:32 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 [this message]
2007-02-19  9:24   ` Ludovic Courtès
2007-02-21 22:21     ` Kevin Ryde
2007-02-22  9:20       ` Ludovic Courtès
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=877iufhwj6.fsf@zip.com.au \
    --to=user42@zip.com.au \
    --cc=guile-devel@gnu.org \
    --cc=ludo@chbouib.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).