[bug#70398,5/5] packages: Reduce code bloat due to list allocation in input fields.
Commit Message
* guix/packages.scm (add-input-labels): New procedure.
(sanitize-inputs): Add case for (list …).
Change-Id: Ice8241508ded51efd38867b97ca19c262b8c4363
---
guix/packages.scm | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
Comments
Hi Ludo,
On lun., 15 avril 2024 at 17:37, Ludovic Courtès <ludo@gnu.org> wrote:
> + ((_ (list args ...))
> + ;; As of 3.0.9, (list ...) is open-coded, which can lead to a long list
> + ;; of instructions. To reduce code bloat in package modules where input
> + ;; fields may create such lists, move list allocation to the callee.
> + (add-input-labels args ...))
I am not sure to understand: « (list ...) is open-coded, which can lead
to a long list of instructions. ». Well, irrelevant for .go size but
why not something like:
((_ (list args . rest))
(apply add-inputs-labels (append args rest)))
It would not change for .go size but it would change for run-time if
it’s a long list, no?
Cheers,
simon
Simon Tournier <zimon.toutoune@gmail.com> skribis:
> On lun., 15 avril 2024 at 17:37, Ludovic Courtès <ludo@gnu.org> wrote:
>
>> + ((_ (list args ...))
>> + ;; As of 3.0.9, (list ...) is open-coded, which can lead to a long list
>> + ;; of instructions. To reduce code bloat in package modules where input
>> + ;; fields may create such lists, move list allocation to the callee.
>> + (add-input-labels args ...))
>
> I am not sure to understand: « (list ...) is open-coded, which can lead
> to a long list of instructions. ».
This:
--8<---------------cut here---------------start------------->8---
scheme@(guile-user)> ,c (lambda () (list 1 2 3 4))
[...]
8 (allocate-words/immediate 0 2)
9 (scm-set!/immediate 0 0 2)
10 (scm-set!/immediate 0 1 1)
11 (allocate-words/immediate 2 2)
12 (scm-set!/immediate 2 0 3)
13 (scm-set!/immediate 2 1 0)
14 (allocate-words/immediate 3 2)
15 (scm-set!/immediate 3 0 4)
16 (scm-set!/immediate 3 1 2)
17 (allocate-words/immediate 4 2)
18 (scm-set!/immediate 4 0 5)
19 (scm-set!/immediate 4 1 3)
--8<---------------cut here---------------end--------------->8---
> Well, irrelevant for .go size but why not something like:
>
> ((_ (list args . rest))
> (apply add-inputs-labels (append args rest)))
That’s more code and I’m really trying hard to minimize generated code.
:-)
Ludo’.
Hi,
On lun., 15 avril 2024 at 22:31, Ludovic Courtès <ludo@gnu.org> wrote:
>> I am not sure to understand: « (list ...) is open-coded, which can lead
>> to a long list of instructions. ».
>
> This:
>
> --8<---------------cut here---------------start------------->8---
> scheme@(guile-user)> ,c (lambda () (list 1 2 3 4))
>
> [...]
>
> 8 (allocate-words/immediate 0 2)
> 9 (scm-set!/immediate 0 0 2)
> 10 (scm-set!/immediate 0 1 1)
> 11 (allocate-words/immediate 2 2)
> 12 (scm-set!/immediate 2 0 3)
> 13 (scm-set!/immediate 2 1 0)
> 14 (allocate-words/immediate 3 2)
> 15 (scm-set!/immediate 3 0 4)
> 16 (scm-set!/immediate 3 1 2)
> 17 (allocate-words/immediate 4 2)
> 18 (scm-set!/immediate 4 0 5)
> 19 (scm-set!/immediate 4 1 3)
> --8<---------------cut here---------------end--------------->8---
>
>> Well, irrelevant for .go size but why not something like:
>>
>> ((_ (list args . rest))
>> (apply add-inputs-labels (append args rest)))
>
> That’s more code and I’m really trying hard to minimize generated code.
> :-)
Thanks for explaining. :-) Yeah that’s make sense.
Cheers,
simon
@@ -439,16 +439,26 @@ (define (maybe-add-input-labels inputs)
inputs)
(else (map add-input-label inputs))))
+(define (add-input-labels . inputs)
+ "Add labels to all of INPUTS."
+ (map add-input-label inputs))
+
(define-syntax sanitize-inputs
;; This is written as a macro rather than as a 'define-inlinable' procedure
;; because as of Guile 3.0.9, peval can handle (null? '()) but not
;; (null? (list x y z)); that residual 'null?' test contributes to code
;; bloat.
- (syntax-rules (quote)
+ (syntax-rules (quote list)
"Sanitize INPUTS by turning it into a list of name/package tuples if it's
not already the case."
((_ '()) '())
- ((_ inputs) (maybe-add-input-labels inputs))))
+ ((_ (list args ...))
+ ;; As of 3.0.9, (list ...) is open-coded, which can lead to a long list
+ ;; of instructions. To reduce code bloat in package modules where input
+ ;; fields may create such lists, move list allocation to the callee.
+ (add-input-labels args ...))
+ ((_ inputs)
+ (maybe-add-input-labels inputs))))
(define-syntax current-location-vector
(lambda (s)