unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
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 4/5] packages: ‘define-public’ replacement calls ‘module-export!’ directly.
Date: Mon, 15 Apr 2024 17:37:06 +0200	[thread overview]
Message-ID: <723be7e4e70628f32862b8c1043eee641c4ccf8c.1713194148.git.ludo@gnu.org> (raw)
In-Reply-To: <cover.1713194148.git.ludo@gnu.org>

This reduces code bloat and loading overhead for package modules, which
use ‘define-public’ extensively.

* guix/packages.scm (define-public*): Use ‘define’ followed by
‘module-export!’ directly instead of ‘define-public’.

Change-Id: I7f56d46b391c1e3eeeb0b9a08a9d34b5de341245
---
 guix/packages.scm | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/guix/packages.scm b/guix/packages.scm
index bd6724cdd4..6c697bcc67 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -482,7 +482,8 @@ (define-syntax-parameter current-definition-location
 (define-syntax define-public*
   (lambda (s)
     "Like 'define-public' but set 'current-definition-location' for the
-lexical scope of its body."
+lexical scope of its body.  (This also disables notification of \"module
+observers\", but this is unlikely to affect anyone.)"
     (define location
       (match (syntax-source s)
         (#f #f)
@@ -499,10 +500,21 @@ (define-syntax define-public*
 
     (syntax-case s ()
       ((_ prototype body ...)
-       #`(define-public prototype
-           (syntax-parameterize ((current-definition-location
-                                  (lambda (s) #,location)))
-             body ...))))))
+       (with-syntax ((name (syntax-case #'prototype ()
+                             ((id _ ...) #'id)
+                             (id #'id))))
+         #`(begin
+             (define prototype
+               (syntax-parameterize ((current-definition-location
+                                      (lambda (s) #,location)))
+                 body ...))
+
+             ;; Note: Use 'module-export!' directly to avoid emitting a
+             ;; 'call-with-deferred-observers' call for each 'define-public*'
+             ;; instance, which is not only pointless but also contributes to
+             ;; code bloat and to load-time overhead in package modules.
+             (eval-when (expand load eval)
+               (module-export! (current-module) '(name)))))))))
 
 (define-syntax validate-texinfo
   (let ((validate? (getenv "GUIX_UNINSTALLED")))
-- 
2.41.0





  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 ` [bug#70398] [PATCH 3/5] records: Do not inline the constructor Ludovic Courtès
2024-04-15 15:37 ` Ludovic Courtès [this message]
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=723be7e4e70628f32862b8c1043eee641c4ccf8c.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).