From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Skipping unexec via a big .elc file (was: When should ralloc.c be used?) Date: Sun, 23 Oct 2016 12:44:33 -0400 Message-ID: References: <87twe6sx2g.fsf@users.sourceforge.net> <87eg51ng4r.fsf_-_@users.sourceforge.net> <87k2djwumn.fsf@users.sourceforge.net> <83h98nidvd.fsf@gnu.org> <87eg3rvtsf.fsf@users.sourceforge.net> <83k2dihpm9.fsf@gnu.org> <8760p2wzgj.fsf@users.sourceforge.net> <838ttyhhzu.fsf@gnu.org> <871szqwu51.fsf@users.sourceforge.net> <831szqhbc2.fsf@gnu.org> <87d1itt79z.fsf_-_@users.sourceforge.net> <7baa18d4-2b09-caa8-005e-29008a383ad1@cs.ucla.edu> <83mvhwrgd5.fsf@gnu.org> <8539f38f-9a11-44c3-4de7-bb974c96206c@cs.ucla.edu> <8360ojpndr.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1477241104 14446 195.159.176.226 (23 Oct 2016 16:45:04 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Oct 2016 16:45:04 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 23 18:44:59 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byLtK-000317-78 for ged-emacs-devel@m.gmane.org; Sun, 23 Oct 2016 18:44:58 +0200 Original-Received: from localhost ([::1]:41728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byLtM-0005bj-KZ for ged-emacs-devel@m.gmane.org; Sun, 23 Oct 2016 12:45:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byLtG-0005bT-2T for emacs-devel@gnu.org; Sun, 23 Oct 2016 12:44:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byLtB-0006gR-5x for emacs-devel@gnu.org; Sun, 23 Oct 2016 12:44:54 -0400 Original-Received: from [195.159.176.226] (port=35911 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1byLtA-0006gF-US for emacs-devel@gnu.org; Sun, 23 Oct 2016 12:44:49 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1byLt2-0000fo-CZ for emacs-devel@gnu.org; Sun, 23 Oct 2016 18:44:40 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 98 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:4kJKpplOw+3hIjF5eNkgcJrDwZQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208629 Archived-At: >> If someone wants to do that, great. I'd rather spend my own limited >> cycles on fixing the main problem, which is unexec. > I thought we agreed to get rid of unexec by loading a single .elc file > at startup of Emacs, and remove the distinction between temacs and > Emacs altogether. Is that what you'd like to work on? FWIW, I just did a quick experiment with the patch below which dumps the state of Emacs's obarray after loadup.el into a big "dumped.elc" file. Not sure if such an approach could work, but in any case I expect that a working .elc file should likely be of comparable size. The result is a .elc file of 3.3MB which seems reasonable. When I try to load it, tho, I get: % time src/emacs -Q --batch -l dumped.elc -f kill-emacs src/emacs -Q --batch -l dumped.elc -f kill-emacs 3.50s user 0.00s system 99% cpu 3.506 total % And that's with a warm cache on "i3-4170 CPU @ 3.70GHz" (my first, and still only, CPU that goes beyond 3GHz). So even if there might be ways to speed this up, it doesn't look too promising. Stefan diff --git a/lisp/loadup.el b/lisp/loadup.el index 5c16464..dddd71f 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -474,6 +474,65 @@ invocation-directory) (expand-file-name name invocation-directory) t))) + (message "Dumping into dumped.elc...preparing...") + + ;; Dump the current state into a file so we can reload it! + (with-current-buffer (generate-new-buffer "dumped.elc") + (message "Dumping into dumped.elc...generating...") + (insert ";ELC\^W\^@\^@\^@\n;;; Compiled\n;;; in Emacs version " emacs-version "\n") + (let ((cmds '())) + (setcdr global-buffers-menu-map nil) ;; Get rid of buffer objects! + (mapatoms + (lambda (s) + (when (and (fboundp s) + (not (subrp (symbol-function s))) + ;; FIXME: We need these, but they contain + ;; unprintable objects. + (not (memq s '(rename-buffer)))) + (push `(fset ',s ,(macroexp-quote (symbol-function s))) cmds)) + (when (and (boundp s) (not (keywordp s)) + (not (memq s '(nil t + ;; I think we don't need these! + terminal-frame + ;; FIXME: We need these, but they contain + ;; unprintable objects. + advertised-signature-table + undo-auto--undoably-changed-buffers)))) + ;; FIXME: Don't record in the load-history! + ;; FIXME: Handle varaliases! + (let ((v (symbol-value s))) + (push `(defvar ,s + ,(cond + ((subrp v) + `(symbol-function ',(intern (subr-name v)))) + ((and (markerp v) (null (marker-buffer v))) + '(make-marker)) + ((and (overlayp v) (null (overlay-buffer v))) + '(let ((ol (make-overlay (point-min) (point-min)))) + (delete-overlay ol) + ol)) + (v (macroexp-quote v)))) + cmds))) + (when (symbol-plist s) + (push `(setplist ',s ',(symbol-plist s)) cmds)))) + (message "Dumping into dumped.elc...printing...") + (let ((print-circle t) + (print-gensym t) + (print-quoted t) + (print-level nil) + (print-length nil) + (print-escape-newlines t)) + (print `(progn . ,cmds) (current-buffer))) + (goto-char (point-min)) + (while (re-search-forward " (\\(defvar\\|setplist\\|fset\\) " nil t) + (goto-char (match-beginning 0)) + (delete-char 1) (insert "\n")) + (message "Dumping into dumped.elc...saving...") + (let ((coding-system-for-write 'emacs-internal)) + (write-region (point-min) (point-max) (buffer-name))) + (message "Dumping into dumped.elc...done") + )) + (kill-emacs))) ;; For machines with CANNOT_DUMP defined in config.h,