unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Mark H Weaver <mhw@netris.org>
To: Brian <gomesbascoy@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: Performance impact of top level definitions
Date: Mon, 14 May 2018 22:55:41 -0400	[thread overview]
Message-ID: <87bmdh7hle.fsf@netris.org> (raw)
In-Reply-To: <542e7f030ad122e035a353f44465d4d3158d7f8c.camel@gmail.com> (Brian's message of "Tue, 08 May 2018 22:19:23 -0700")

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  2: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 [this message]
2018-05-15 16:55   ` Brian

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=87bmdh7hle.fsf@netris.org \
    --to=mhw@netris.org \
    --cc=gomesbascoy@gmail.com \
    --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).