mbox series

[bug#70398,0/5] Reduce the size of gnu/packages/*.go files

Message ID cover.1713194148.git.ludo@gnu.org
Headers show
Series Reduce the size of gnu/packages/*.go files | expand

Message

Ludovic Courtès April 15, 2024, 3:27 p.m. UTC
Hello!

As a followup to <https://issues.guix.gnu.org/70280>, I started looking
into the size of Guix itself, and in particular that of gnu/packages/*.go
files.

What follows is a bunch of tricks to reduce code bloat, achieving ~14%
reduction in the size of .go files (~18% if we look at gnu/packages
alone).

About 60% of those files are in the 64–128 KiB range.  Since ELF sections
are currently 64 KiB-aligned (see ‘*lcm-page-size*’ in Guile), we would
save space by ensuring these are sparse files.  To do that, we’ll need to
detect holes when restoring nars and/or to change the nar format to
preserve holes, while also ensuring that when the daemon copies files
around, it also preserves holes.  Work for later!

Thoughts?

Ludo’.

Ludovic Courtès (5):
  records: Do not inline throws for ABI mismatches.
  packages: Reduce bloat induced by ‘sanitize-inputs’.
  records: Do not inline the constructor.
  packages: ‘define-public’ replacement calls ‘module-export!’ directly.
  packages: Reduce code bloat due to list allocation in input fields.

 guix/packages.scm | 53 +++++++++++++++++++++++++++++++++++--------
 guix/records.scm  | 58 ++++++++++++++++++++++++++++++++---------------
 2 files changed, 83 insertions(+), 28 deletions(-)


base-commit: cd45294d576975a3bff2f755764a3f46f09ea6f9

Comments

Ludovic Courtès April 15, 2024, 4:10 p.m. UTC | #1
Ludovic Courtès <ludo@gnu.org> skribis:

> What follows is a bunch of tricks to reduce code bloat, achieving ~14%
> reduction in the size of .go files (~18% if we look at gnu/packages
> alone).

On this topic, you may also like this earlier post:

  https://lists.gnu.org/archive/html/guix-devel/2020-06/msg00071.html

Ludo’.
Ludovic Courtès April 15, 2024, 4:24 p.m. UTC | #2
Ludovic Courtès <ludo@gnu.org> skribis:

> What follows is a bunch of tricks to reduce code bloat, achieving ~14%
> reduction in the size of .go files (~18% if we look at gnu/packages
> alone).

On this topic, you may also like this earlier post:

  https://lists.gnu.org/archive/html/guix-devel/2020-06/msg00071.html

Ludo’.
Simon Tournier April 15, 2024, 6:06 p.m. UTC | #3
Hi,

On lun., 15 avril 2024 at 17:27, Ludovic Courtès <ludo@gnu.org> wrote:

> What follows is a bunch of tricks to reduce code bloat, achieving ~14%
> reduction in the size of .go files (~18% if we look at gnu/packages
> alone).

If have not checked that the reduction would be of ~18%.  From my
understanding, the patch set LGTM; modulo an unrelated comment about
ellipsis and potential quadratic penalty on performances.


> About 60% of those files are in the 64–128 KiB range.  Since ELF sections
> are currently 64 KiB-aligned (see ‘*lcm-page-size*’ in Guile), we would
> save space by ensuring these are sparse files.  To do that, we’ll need to
> detect holes when restoring nars and/or to change the nar format to
> preserve holes, while also ensuring that when the daemon copies files
> around, it also preserves holes.  Work for later!

Since [1], I think that compiling a generic Guile record for <package>
is touching the limit of DSL. :-) Other said, I think the binary
(compiled) representation of records <package> should be specific and
thus optimized.  Work for after later. ;-)

Cheers,
simon


1: How many bytes do we add (closure of guix) when adding one new package?
Simon Tournier <zimon.toutoune@gmail.com>
Thu, 25 May 2023 20:24:30 +0200
id:87r0r4uv4x.fsf@gmail.com
https://lists.gnu.org/archive/html/guix-devel/2023-05
https://yhetil.org/guix/87r0r4uv4x.fsf@gmail.com
Simon Tournier April 15, 2024, 6:49 p.m. UTC | #4
Hi,

On lun., 15 avril 2024 at 18:10, Ludovic Courtès <ludo@gnu.org> wrote:
> Ludovic Courtès <ludo@gnu.org> skribis:
>
>> What follows is a bunch of tricks to reduce code bloat, achieving ~14%
>> reduction in the size of .go files (~18% if we look at gnu/packages
>> alone).
>
> On this topic, you may also like this earlier post:
>
>   https://lists.gnu.org/archive/html/guix-devel/2020-06/msg00071.html

And unrelated to this patch set, let also mention this other thread [1],
comparing (btrfs):

--8<---------------cut here---------------start------------->8---
# compsize /gnu/store/nqrb3g4l59wd74w8mr9v0b992bj2sd1w-guix-d62c9b267-modules/lib/guile/3.0/site-ccache/gnu
Processed 503 files, 1317 regular extents (1317 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       27%       40M         144M         144M
none       100%       10M          10M          10M
zstd        22%       30M         133M         133M

# compsize /gnu/store/s6rqlhqr750k44ynkqqj5mwjj2cs2yln-guix-a09968565-modules/lib/guile/3.0/site-ccache/gnu
Processed 530 files, 1169 regular extents (1169 refs), 0 inline.
Type       Perc     Disk Usage   Uncompressed Referenced
TOTAL       19%       22M         116M         116M
none       100%       32K          32K          32K
zstd        19%       22M         116M         116M
--8<---------------cut here---------------end--------------->8---

Compared to (ext4):

--8<---------------cut here---------------start------------->8---
145M /gnu/store/nqrb3g4l59wd74w8mr9v0b992bj2sd1w-guix-d62c9b267-modules/lib/guile/3.0/site-ccache/gnu
117M /gnu/store/s6rqlhqr750k44ynkqqj5mwjj2cs2yln-guix-a09968565-modules/lib/guile/3.0/site-ccache/gnu
--8<---------------cut here---------------end--------------->8---

Somehow, these packages .go files could be compressed and decompressed
on the fly when needed.

Cheers,
simon


1: Re: How many bytes do we add (closure of guix) when adding one new package?
Guillaume Le Vaillant <glv@posteo.net>
Wed, 31 May 2023 12:47:09 +0000
id:87h6rsll5i.fsf@kitej
https://lists.gnu.org/archive/html/guix-devel/2023-05
https://yhetil.org/guix/87h6rsll5i.fsf@kitej
Ludovic Courtès May 4, 2024, 5:17 p.m. UTC | #5
Hello,

Pushed!

  402d0a9b9d2 * packages: Reduce code bloat due to list allocation in input fields.
  76127069e02 * packages: ‘define-public’ replacement calls ‘module-export!’ directly.
  c14b8636fba * records: Do not inline the constructor.
  b011ef4378a * packages: Reduce bloat induced by ‘sanitize-inputs’.
  2f93e1682a0 * records: Do not inline throws for ABI mismatches.

Thanks,
Ludo’.