summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2024-04-11 09:17:43 +0200
committerLudovic Courtès <ludo@gnu.org>2024-05-04 19:14:24 +0200
commitc14b8636fbac9826115f4524d500536d54c15625 (patch)
tree7aa3865cac8d33732f7c98dce3bdecae4fd2e8a0
parentb011ef4378aa40bb25db3022906eac378472cd83 (diff)
downloadguix-patches-c14b8636fbac9826115f4524d500536d54c15625.tar
guix-patches-c14b8636fbac9826115f4524d500536d54c15625.tar.gz
records: Do not inline the constructor.
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
-rw-r--r--guix/records.scm47
1 files 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 @@ of TYPE matches the expansion-time ABI."
(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 @@ of TYPE matches the expansion-time ABI."
(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 @@ inherited."
(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 @@ of a record instantiation"
#'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