From: "Ludovic Courtès" <ludo@gnu.org>
To: 70398@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
"Christopher Baines" <guix@cbaines.net>,
"Josselin Poiret" <dev@jpoiret.xyz>,
"Ludovic Courtès" <ludo@gnu.org>,
"Mathieu Othacehe" <othacehe@gnu.org>,
"Ricardo Wurmus" <rekado@elephly.net>,
"Simon Tournier" <zimon.toutoune@gmail.com>,
"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#70398] [PATCH 3/5] records: Do not inline the constructor.
Date: Mon, 15 Apr 2024 17:37:05 +0200 [thread overview]
Message-ID: <f09974509ebd1aeffed10a2db08720bcedd039b5.1713194148.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1713194148.git.ludo@gnu.org>
Struct initialization uses one instruction per field, which contributes
to code bloat in the case of package modules. With this change, the
‘.rtl-text’ section of ‘gnu/packages/tex.go’ goes from 7,334,508 B to
6,356,592 B (-13%; -7% on the whole file size), which alone is still
larger than the source file (4,2 MB).
* guix/records.scm (make-syntactic-constructor)[record-inheritance]: Use
CTOR instead of ‘make-struct/no-tail’.
Pass ABI-COOKIE as the first argument to CTOR.
(define-record-type*): Define CTOR-PROCEDURE and pass it to
‘make-syntactic-constructor’.
Change-Id: Ifd7b4e884e9fbf21c43fb4c3ad963126ef5cb476
---
guix/records.scm | 47 +++++++++++++++++++++++++++++++++--------------
1 file changed, 33 insertions(+), 14 deletions(-)
diff --git a/guix/records.scm b/guix/records.scm
index 48637ea0a4..dca1e3c2e7 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -164,16 +164,16 @@ (define-syntax make-syntactic-constructor
(record-error 'name s "extraneous field initializers ~a"
unexpected)))
- #`(make-struct/no-tail type
- #,@(map (lambda (field index)
- (or (field-inherited-value field)
- (if (innate-field? field)
- (wrap-field-value
- field (field-default-value field))
- #`(struct-ref #,orig-record
- #,index))))
- '(expected ...)
- (iota (length '(expected ...))))))
+ #`(ctor #,abi-cookie
+ #,@(map (lambda (field index)
+ (or (field-inherited-value field)
+ (if (innate-field? field)
+ (wrap-field-value
+ field (field-default-value field))
+ #`(struct-ref #,orig-record
+ #,index))))
+ '(expected ...)
+ (iota (length '(expected ...))))))
(define (thunked-field? f)
(memq (syntax->datum f) 'thunked))
@@ -249,8 +249,8 @@ (define-syntax make-syntactic-constructor
(cond ((lset= eq? fields '(expected ...))
#`(let* #,(field-bindings
#'((field value) (... ...)))
- #,(abi-check #'type abi-cookie)
- (ctor #,@(map field-value '(expected ...)))))
+ (ctor #,abi-cookie
+ #,@(map field-value '(expected ...)))))
((pair? (lset-difference eq? fields
'(expected ...)))
(record-error 'name s
@@ -435,7 +435,13 @@ (define-syntax define-record-type*
(sanitizers (filter-map field-sanitizer
#'((field properties ...) ...)))
(cookie (compute-abi-cookie field-spec)))
- (with-syntax (((field-spec* ...)
+ (with-syntax ((ctor-procedure
+ (datum->syntax
+ #'ctor
+ (symbol-append (string->symbol " %")
+ (syntax->datum #'ctor)
+ '-procedure/abi-check)))
+ ((field-spec* ...)
(map field-spec->srfi-9 field-spec))
((field-type ...)
(map (match-lambda
@@ -502,7 +508,20 @@ (define-syntax define-record-type*
#'id)))))))
thunked-field-accessor ...
delayed-field-accessor ...
- (make-syntactic-constructor type syntactic-ctor ctor
+
+ (define ctor-procedure
+ ;; This procedure is *not* inlined, to reduce code bloat
+ ;; (struct initialization takes at least one instruction per
+ ;; field).
+ (case-lambda
+ ((cookie field ...)
+ (unless (eq? cookie #,cookie)
+ (record-abi-mismatch-error type))
+ (ctor field ...))
+ (_
+ (record-abi-mismatch-error type))))
+
+ (make-syntactic-constructor type syntactic-ctor ctor-procedure
(field ...)
#:abi-cookie #,cookie
#:thunked #,thunked
--
2.41.0
next prev parent reply other threads:[~2024-04-15 15:39 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 15:27 [bug#70398] [PATCH 0/5] Reduce the size of gnu/packages/*.go files Ludovic Courtès
2024-04-15 15:37 ` [bug#70398] [PATCH 1/5] records: Do not inline throws for ABI mismatches Ludovic Courtès
2024-04-15 15:37 ` [bug#70398] [PATCH 2/5] packages: Reduce bloat induced by ‘sanitize-inputs’ Ludovic Courtès
2024-04-15 15:37 ` Ludovic Courtès [this message]
2024-04-15 15:37 ` [bug#70398] [PATCH 4/5] packages: ‘define-public’ replacement calls ‘module-export!’ directly Ludovic Courtès
2024-04-15 15:37 ` [bug#70398] [PATCH 5/5] packages: Reduce code bloat due to list allocation in input fields Ludovic Courtès
2024-04-15 17:56 ` Simon Tournier
2024-04-15 20:31 ` Ludovic Courtès
2024-04-22 0:15 ` Simon Tournier
2024-04-15 16:10 ` [bug#70398] [PATCH 0/5] Reduce the size of gnu/packages/*.go files Ludovic Courtès
2024-04-15 18:49 ` Simon Tournier
2024-04-15 16:24 ` Ludovic Courtès
2024-04-15 18:06 ` Simon Tournier
2024-05-04 17:17 ` bug#70398: " Ludovic Courtès
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://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f09974509ebd1aeffed10a2db08720bcedd039b5.1713194148.git.ludo@gnu.org \
--to=ludo@gnu.org \
--cc=70398@debbugs.gnu.org \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=me@tobias.gr \
--cc=othacehe@gnu.org \
--cc=rekado@elephly.net \
--cc=zimon.toutoune@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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
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).