unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: guile-devel@gnu.org
Subject: Re: A lexical use-modules?
Date: Sun, 27 Mar 2022 12:40:03 +0200	[thread overview]
Message-ID: <fd0932c1c8902bbf78a52314337384ebcdf0656d.camel@telenet.be> (raw)
In-Reply-To: <CAGua6m1eNt5ABwDGT_3ifwCjT5YQkpd8W5XBjgwYGZE2B8WW0g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]

Stefan Israelsson Tampe schreef op zo 27-03-2022 om 11:53 [+0200]:
Hmm actually you only have lexical macros that reference module
variables. That is not lexical variables which have more optimisation
associated with it at least used to. But is better speedwise than the
hash lookups I suggested. Anyhow you can create a let with local
variables and set them from the module dynamically. Maybe wingos recent
work mean that your approach is best. Would be interesting to do some
tests to see. 

Optimisations are performed at expansion time:

(macroexpand
  #'(let ()
      (use-module/lexical (ice-9 exceptions))
      (do-stuff)))
;; the unused imports disappeared!
$6 = #<tree-il (call (toplevel do-stuff))> 

A variable is only dereferenced when it is used:

,optimize
  (let ()
    (use-module/lexical (ice-9 exceptions))
    (lambda () raise-continuable))
$7 = (lambda ()
  (@ (ice-9 exceptions) raise-continuable))

So lexical imports should be as fast as directly writing
(@ (foo) bar).  I don't see how creating new modules at runtime and
using 'module-ref' could make things faster (*) here, given that it just
seems like an extra layer of indirection and it probably prevents things
like inlining.

(*) I'm only counting runtime here, not compilation time.

Greetings,
Maxime.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

  parent reply	other threads:[~2022-03-27 10:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-26 19:21 A lexical use-modules? Maxime Devos
     [not found] ` <CAGua6m33_=0=B9jaL4Jw7yP=yycD0eFxiAMK62iVBPuUV8F2wg@mail.gmail.com>
     [not found]   ` <4fb1eef748667d5e33d9df674af77ff52d30cd00.camel@telenet.be>
     [not found]     ` <CAGua6m1eNt5ABwDGT_3ifwCjT5YQkpd8W5XBjgwYGZE2B8WW0g@mail.gmail.com>
2022-03-27 10:40       ` Maxime Devos [this message]
     [not found]         ` <CAGua6m0H1CZOpDtCUgX=+h6P+zT74_VEA8etQKKs5JwVGLurGQ@mail.gmail.com>
2022-03-27 15:11           ` Maxime Devos
2022-03-29 13:20 ` Ludovic Courtès
2022-03-29 14:59 ` Maxime Devos

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=fd0932c1c8902bbf78a52314337384ebcdf0656d.camel@telenet.be \
    --to=maximedevos@telenet.be \
    --cc=guile-devel@gnu.org \
    --cc=stefan.itampe@gmail.com \
    /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).