guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A lexical use-modules?


From: Maxime Devos
Subject: Re: A lexical use-modules?
Date: Sun, 27 Mar 2022 12:40:03 +0200
User-agent: Evolution 3.38.3-1

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: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]