1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Deduplicate bytecode strings in each top-level form

This cheap device enables sharing of byte-code for local functions
that only differ in their constant vectors (and/or doc strings etc).
It makes the .elc files smaller by about 150 KB, and should reduce
in-memory usage a little as well.

* lisp/emacs-lisp/bytecomp.el (bytecomp--code-strings): New.
(byte-compile-from-buffer, byte-compile-flush-pending)
(byte-compile-lambda): Hash-cons byte-code locally.
This commit is contained in:
Mattias Engdegård 2025-11-30 19:38:39 +01:00
parent 4b55e56232
commit 310ec70648

View file

@ -495,6 +495,9 @@ Filled in `cconv-analyze-form' but initialized and consulted here.")
(defvar byte-compiler-error-flag)
(defvar bytecomp--code-strings nil
"List of unique bytecode strings in this top-level form, for deduplication.")
(defun byte-compile-recurse-toplevel (form non-toplevel-case)
"Implement `eval-when-compile' and `eval-and-compile'.
Return the compile-time value of FORM."
@ -2417,6 +2420,7 @@ With argument ARG, insert value in current buffer after the form."
(byte-compile-depth 0)
(byte-compile-maxdepth 0)
(byte-compile-output nil)
(bytecomp--code-strings nil)
;; #### This is bound in b-c-close-variables.
;; (byte-compile-warnings byte-compile-warnings)
(symbols-with-pos-enabled t))
@ -2580,6 +2584,7 @@ Call from the source buffer."
byte-compile-depth 0
byte-compile-maxdepth 0
byte-compile-output nil
bytecomp--code-strings nil
byte-compile-jump-tables nil))))
(defun byte-compile-preprocess (form &optional _for-effect)
@ -3162,9 +3167,16 @@ lambda-expression."
(if lexical-binding
(byte-compile-make-args-desc arglist)
bare-arglist)
;; code string, deduplicated
(let* ((code (cadr compiled))
(prev (member code bytecomp--code-strings)))
(if prev
(car prev)
(push code bytecomp--code-strings)
code))
(append
;; byte-string, constants-vector, stack depth
(cdr compiled)
;; constants-vector and stack depth
(drop 2 compiled)
;; optionally, the doc string.
(when (or doc int) (list doc))
;; optionally, the interactive spec (and the modes the