unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Brian <gomesbascoy@gmail.com>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-devel@gnu.org
Subject: Re: Performance impact of top level definitions
Date: Tue, 15 May 2018 09:55:34 -0700	[thread overview]
Message-ID: <d59ac3864baa3d2a352068b4c0f4edfd9079f438.camel@gmail.com> (raw)
In-Reply-To: <87bmdh7hle.fsf@netris.org>

Hi Mark,

Thanks for that explanation, it makes sense now to me.

Cheers!


On Mon, 2018-05-14 at 22:55 -0400, Mark H Weaver wrote:
> Hi Brian,
> 
> Brian <gomesbascoy@gmail.com> writes:
> 
> > Today I found that top level defines have a significant performance
> > impact on Guile (2.2.3). The following program takes about 108
> > seconds
> > to complete on my ThinkPad (an i5-5200U with Arch Linux):
> 
> [...]
> > By simply wrapping that code in a lambda the program finished in
> > about
> > 47 seconds. Using lets instead of defines is equally effective.
> > 
> > I was quite surprised because I initially thought some optimization
> > would just substitute those useless nodes symbols away, but it
> > seems
> > like that's not the case...
> 
> Right.  The problem is that toplevel variables can be mutated by
> arbitrary code from other modules, e.g. by 'module-set!', so the
> compiler cannot make any assumptions about what values those
> variables
> will contain at runtime.
> 
> For non-toplevel variables, the situation is quite different.  In
> Scheme, non-toplevel variables can be accessed only from within their
> lexical scope, so if such a variable is not 'set!' from within its
> scope, the compiler knows that it can never be mutated.  In that
> case,
> it can assume that the variable will always contain its initial
> value,
> which enables a great many optimizations including partial
> evaluation.
> 
>        Mark



      reply	other threads:[~2018-05-15 16:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-09  5:19 Performance impact of top level definitions Brian
2018-05-15  2:55 ` Mark H Weaver
2018-05-15 16:55   ` Brian [this message]

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=d59ac3864baa3d2a352068b4c0f4edfd9079f438.camel@gmail.com \
    --to=gomesbascoy@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=mhw@netris.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).