From: Andreas Rottmann <a.rottmann@gmx.at>
To: ludo@gnu.org (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: define-inlinable
Date: Wed, 06 Apr 2011 23:30:29 +0200 [thread overview]
Message-ID: <878vvngj9m.fsf@gmx.at> (raw)
In-Reply-To: <874o6btuuf.fsf_-_@gnu.org> ("Ludovic Courtès"'s message of "Wed, 06 Apr 2011 14:42:00 +0200")
[-- Attachment #1: Type: text/plain, Size: 2777 bytes --]
ludo@gnu.org (Ludovic Courtès) writes:
> Hello!
>
> Andreas Rottmann <a.rottmann@gmx.at> writes:
>
>> Subject: Move `define-inlinable' into the default namespace
>>
>> +@node Inlinable Procedures
>> +@subsection Inlinable Procedures
>> +
>> +You can define an ``inlinable procedure'' by using
>
> Use @dfn{inlinable procedure} here.
>
Done.
>> +@code{define-inlinable} instead of @code{define}. An inlinable procedure
>
> I prefer two-spaces-after-period, but there’s no consensus.
>
I try to use two spaces in English text as well, but being a German
native speaker (where this is against typographical rules, AFAIK), I
slip sometimes. Fixed.
>> +behaves the same as a regular procedure, but direct calls will result in
>> +the procedure body being inlined into the caller.
>> +
>> +Making a procedure inlinable eliminates the overhead of the call,
>
> How about:
>
> Procedures defined with @code{define-inlinable} are @emph{always}
> inlined, at all call sites. This eliminates function call overhead at
> the expense of an increase in code size.
>
Folded in, with the addition of using ".., at _direct_ call sites.".
There's no inlining happening when you use `apply', or rebind the
procedure with `let'. Should this be made more explicit?
>> but at
>> +the same time means that the caller will not transparently use the new
>> +definition if the inline procedure is redefined.
>
> ... redefined using @code{set!}.
>
I don't agree with that one: there are multiple ways a procedure can get
"redefined", `set!' being just one of them. I was actually thinking
more of re-evaluating the procedure definition or something like
`geiser-compile-file', hence I left the text like it was, being more
vague.
>> Inlinable procedures
>> +will also not deal nicely with debugging and tracing.
>
> Instead of “not deal nicely”, what about something like:
>
> It is not possible to trace an inlined procedures or install a
> breakpoint in it (@pxref{Traps}).
>
Done.
>> Therefore, you
>> +should not make a procedure inlinable unless it demonstrably improves
>> +performance in a crucial way.
>> +
>> +In general, only small procedures should be considered for inlining, as
>> +making large procedures inlinable will probably result in an increase in
>> +code size. Additionally, the elimination of the call overhead rarely
>> +matters for for large procedures.
>> +
>> +@deffn {Scheme Syntax} define-inlinable (name parameter ...) . body
>
> I’d write “body ...” instead of “. body”. Besides being aesthetically
> nicer, the former matches a proper list whereas the latter matches a
> pair.
>
Agreed, and done.
Updated patch attached, is it OK to push this way?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: refactor-define-inlinable.diff --]
[-- Type: text/x-diff, Size: 6178 bytes --]
From: Andreas Rottmann <a.rottmann@gmx.at>
Subject: Move `define-inlinable' into the default namespace
* module/ice-9/boot-9.scm (define-inlineable): Moved here from SRFI-9.
* module/srfi/srfi-9 (define-inlinable): Removed here.
* doc/ref/api-procedures.texi (Inlinable Procedures): Add subsection
about `define-inlinable'.
---
doc/ref/api-procedures.texi | 29 ++++++++++++++++++++++++++++-
module/ice-9/boot-9.scm | 36 ++++++++++++++++++++++++++++++++++++
module/srfi/srfi-9.scm | 32 --------------------------------
3 files changed, 64 insertions(+), 33 deletions(-)
diff --git a/doc/ref/api-procedures.texi b/doc/ref/api-procedures.texi
index 02889c4..5c6d380 100644
--- a/doc/ref/api-procedures.texi
+++ b/doc/ref/api-procedures.texi
@@ -1,6 +1,6 @@
@c -*-texinfo-*-
@c This is part of the GNU Guile Reference Manual.
-@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010
+@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2009, 2010, 2011
@c Free Software Foundation, Inc.
@c See the file guile.texi for copying conditions.
@@ -16,6 +16,7 @@
* Higher-Order Functions:: Function that take or return functions.
* Procedure Properties:: Procedure properties and meta-information.
* Procedures with Setters:: Procedures with setters.
+* Inlinable Procedures:: Procedures that can be inlined.
@end menu
@@ -797,6 +798,32 @@ Return the setter of @var{proc}, which must be either a procedure with
setter or an operator struct.
@end deffn
+@node Inlinable Procedures
+@subsection Inlinable Procedures
+
+You can define an @dfn{inlinable procedure} by using
+@code{define-inlinable} instead of @code{define}. An inlinable
+procedure behaves the same as a regular procedure, but direct calls will
+result in the procedure body being inlined into the caller.
+
+Procedures defined with @code{define-inlinable} are @emph{always}
+inlined, at all direct call sites. This eliminates function call
+overhead at the expense of an increase in code size. Additionally, the
+caller will not transparently use the new definition if the inline
+procedure is redefined. It is not possible to trace an inlined
+procedures or install a breakpoint in it (@pxref{Traps}). For these
+reasons, you should not make a procedure inlinable unless it
+demonstrably improves performance in a crucial way.
+
+In general, only small procedures should be considered for inlining, as
+making large procedures inlinable will probably result in an increase in
+code size. Additionally, the elimination of the call overhead rarely
+matters for for large procedures.
+
+@deffn {Scheme Syntax} define-inlinable (name parameter ...) body ...
+Define @var{name} as a procedure with parameters @var{parameter}s and
+body @var{body}.
+@end deffn
@c Local Variables:
@c TeX-master: "guile.texi"
diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm
index 33aa333..327e3fa 100644
--- a/module/ice-9/boot-9.scm
+++ b/module/ice-9/boot-9.scm
@@ -3497,6 +3497,42 @@ module '(ice-9 q) '(make-q q-length))}."
x)))))
\f
+;;; Defining transparently inlinable procedures
+;;;
+
+(define-syntax define-inlinable
+ ;; Define a macro and a procedure such that direct calls are inlined, via
+ ;; the macro expansion, whereas references in non-call contexts refer to
+ ;; the procedure. Inspired by the `define-integrable' macro by Dybvig et al.
+ (lambda (x)
+ ;; Use a space in the prefix to avoid potential -Wunused-toplevel
+ ;; warning
+ (define prefix (string->symbol "% "))
+ (define (make-procedure-name name)
+ (datum->syntax name
+ (symbol-append prefix (syntax->datum name)
+ '-procedure)))
+
+ (syntax-case x ()
+ ((_ (name formals ...) body ...)
+ (identifier? #'name)
+ (with-syntax ((proc-name (make-procedure-name #'name))
+ ((args ...) (generate-temporaries #'(formals ...))))
+ #`(begin
+ (define (proc-name formals ...)
+ body ...)
+ (define-syntax name
+ (lambda (x)
+ (syntax-case x ()
+ ((_ args ...)
+ #'((lambda (formals ...)
+ body ...)
+ args ...))
+ (_
+ (identifier? x)
+ #'proc-name))))))))))
+
+\f
(define using-readline?
(let ((using-readline? (make-fluid)))
diff --git a/module/srfi/srfi-9.scm b/module/srfi/srfi-9.scm
index f9449a6..ad9e95d 100644
--- a/module/srfi/srfi-9.scm
+++ b/module/srfi/srfi-9.scm
@@ -64,38 +64,6 @@
(cond-expand-provide (current-module) '(srfi-9))
-(define-syntax define-inlinable
- ;; Define a macro and a procedure such that direct calls are inlined, via
- ;; the macro expansion, whereas references in non-call contexts refer to
- ;; the procedure. Inspired by the `define-integrable' macro by Dybvig et al.
- (lambda (x)
- ;; Use a space in the prefix to avoid potential -Wunused-toplevel
- ;; warning
- (define prefix (string->symbol "% "))
- (define (make-procedure-name name)
- (datum->syntax name
- (symbol-append prefix (syntax->datum name)
- '-procedure)))
-
- (syntax-case x ()
- ((_ (name formals ...) body ...)
- (identifier? #'name)
- (with-syntax ((proc-name (make-procedure-name #'name))
- ((args ...) (generate-temporaries #'(formals ...))))
- #`(begin
- (define (proc-name formals ...)
- body ...)
- (define-syntax name
- (lambda (x)
- (syntax-case x ()
- ((_ args ...)
- #'((lambda (formals ...)
- body ...)
- args ...))
- (_
- (identifier? x)
- #'proc-name))))))))))
-
(define-syntax define-record-type
(lambda (x)
(define (field-identifiers field-specs)
--
tg: (ce60660..) t/refactor-define-inlinable (depends on: stable-2.0)
[-- Attachment #3: Type: text/plain, Size: 77 bytes --]
Thanks for the review, Rotty
--
Andreas Rottmann -- <http://rotty.yi.org/>
next prev parent reply other threads:[~2011-04-06 21:30 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-22 23:20 Take some lowhanging fruit to speed up R6RS fixnum operations Andreas Rottmann
2011-03-22 23:20 ` [PATCH] " Andreas Rottmann
2011-03-24 21:51 ` Ludovic Courtès
2011-03-24 23:42 ` Andreas Rottmann
2011-03-25 12:16 ` Andreas Rottmann
2011-03-27 15:19 ` Ludovic Courtès
2011-03-27 22:20 ` Andreas Rottmann
2011-03-29 11:05 ` Andy Wingo
2011-03-30 1:37 ` Andreas Rottmann
2011-03-30 10:31 ` Andreas Rottmann
2011-03-30 10:58 ` Andreas Rottmann
2011-04-02 17:42 ` R6RS fixnum arithmetic optimizations Andreas Rottmann
2011-04-02 17:42 ` [PATCH 1/3] Add a few benchmarks for R6RS fixnum arithmetic Andreas Rottmann
2011-04-02 17:42 ` [PATCH 2/3] Several optimizations " Andreas Rottmann
2011-04-02 17:42 ` [PATCH 3/3] Add `fixnum?' VM primitive Andreas Rottmann
2011-04-04 21:53 ` Andy Wingo
2011-04-05 0:14 ` Andreas Rottmann
2011-04-06 12:42 ` define-inlinable Ludovic Courtès
2011-04-06 21:30 ` Andreas Rottmann [this message]
2011-04-06 22:24 ` define-inlinable Ludovic Courtès
2011-04-11 16:56 ` define-inlinable Andy Wingo
2011-04-11 20:01 ` define-inlinable Ludovic Courtès
2011-04-11 21:05 ` define-inlinable Andy Wingo
2011-04-11 22:11 ` define-inlinable Andreas Rottmann
2011-04-07 15:57 ` [PATCH 3/3] Add `fixnum?' VM primitive Ludovic Courtès
2011-04-04 21:28 ` Take some lowhanging fruit to speed up R6RS fixnum operations Andy Wingo
2011-04-04 22:00 ` Andreas Rottmann
2011-04-04 22:12 ` Andy Wingo
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=878vvngj9m.fsf@gmx.at \
--to=a.rottmann@gmx.at \
--cc=guile-devel@gnu.org \
--cc=ludo@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).