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: Re: Skipping unexec via a big .elc file Date: Mon, 31 Oct 2016 10:27:02 -0400 Message-ID: References: <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> <83shrnm0k1.fsf@gnu.org> <075B0922-F07A-4FBA-AE71-027E964A5ED4@raeburn.org> <54AAC13A-CF56-4393-A932-DC6CBBF51259@raeburn.org> <3CC6BB36-1794-4202-8243-132E0345B236@raeburn.org> <52BDCC33-546C-4F47-A230-00EBC813B038@raeburn.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1477925775 9358 195.159.176.226 (31 Oct 2016 14:56:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 31 Oct 2016 14:56:15 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Oct 31 15:56:11 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 1c1Dzj-0005ZR-Cr for ged-emacs-devel@m.gmane.org; Mon, 31 Oct 2016 15:55:27 +0100 Original-Received: from localhost ([::1]:36128 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1Dzl-0004TG-Uc for ged-emacs-devel@m.gmane.org; Mon, 31 Oct 2016 10:55:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c1DZK-0006YY-TL for emacs-devel@gnu.org; Mon, 31 Oct 2016 10:28:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c1DZH-0000Ue-NM for emacs-devel@gnu.org; Mon, 31 Oct 2016 10:28:10 -0400 Original-Received: from [195.159.176.226] (port=46409 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c1DZH-0000UG-Ci for emacs-devel@gnu.org; Mon, 31 Oct 2016 10:28:07 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1c1DYn-0001PI-SJ for emacs-devel@gnu.org; Mon, 31 Oct 2016 15:27:37 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 257 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:bAlvs02LCxt2H8G7rvXYTNQDABQ= 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:209017 Archived-At: > I switched over to a pair of hash tables and the run time is just under 0.2s > on my test machine now. Profiling reports are now topped by read1, > readchar, and readbyte_from_file (now including the expanded getc_unlocked > calls), accounting for about 30% of the CPU time between them. The hash > functions and substitute_object_recurse are not taking a significant amount > of time. BTW, I don't know if you've tried to make that dumped file work correctly, but in case you haven't here's my latest attempt. It mostly works, tho there are still issues such as the fact that the global-font-lock-mode still fails to be properly enabled. Stefan diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 310ca29..9ca53eb 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -439,7 +439,8 @@ macroexp--const-symbol-p (or (memq symbol '(nil t)) (keywordp symbol) (if any-value - (or (memq symbol byte-compile-const-variables) + (or (and (boundp 'byte-compile-const-variables) + (memq symbol byte-compile-const-variables)) ;; FIXME: We should provide a less intrusive way to find out ;; if a variable is "constant". (and (boundp symbol) diff --git a/lisp/international/mule.el b/lisp/international/mule.el index 21ab7e1..bb4808b 100644 --- a/lisp/international/mule.el +++ b/lisp/international/mule.el @@ -290,7 +290,7 @@ define-charset elt)) props)) (setcdr (assq :plist attrs) props) - + (put name 'internal--charset-args (mapcar #'cdr attrs)) (apply 'define-charset-internal name (mapcar 'cdr attrs)))) @@ -911,6 +911,8 @@ define-coding-system (cons :name (cons name (cons :docstring (cons (purecopy docstring) props))))) (setcdr (assq :plist common-attrs) props) + (put name 'internal--cs-args + (mapcar #'cdr (append common-attrs spec-attrs))) (apply 'define-coding-system-internal name (mapcar 'cdr (append common-attrs spec-attrs))))) diff --git a/lisp/loadup.el b/lisp/loadup.el index 21c64a8..5967334 100644 --- a/lisp/loadup.el +++ b/lisp/loadup.el @@ -1,4 +1,4 @@ -;;; loadup.el --- load up standardly loaded Lisp files for Emacs +;;; loadup.el --- load up standardly loaded Lisp files for Emacs -*- lexical-binding:t -*- ;; Copyright (C) 1985-1986, 1992, 1994, 2001-2016 Free Software ;; Foundation, Inc. @@ -461,6 +461,150 @@ 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! + (message "Dumping into dumped.elc...generating...") + (let ((faces '()) + (coding-systems '()) (coding-system-aliases '()) + (charsets '()) (charset-aliases '()) + (cmds '())) + (setcdr global-buffers-menu-map nil) ;; Get rid of buffer objects! + (mapatoms + (lambda (s) + (when (fboundp s) + (if (subrp (symbol-function s)) + ;; subr objects aren't readable! + (unless (equal (symbol-name s) (subr-name (symbol-function s))) + (push `(fset ',s (symbol-function ',(intern (subr-name (symbol-function s))))) cmds)) + (if (memq s '(rename-buffer)) + ;; FIXME: We need these, but they contain + ;; unprintable objects. + nil + (push `(fset ',s ,(macroexp-quote (symbol-function s))) + cmds)))) + (when (and (boundp s) + (not (macroexp--const-symbol-p s 'any-value)) + ;; I think we don't need/want these! + (not (memq s '(terminal-frame obarray + initial-window-system window-system + ;; custom-delayed-init-variables + exec-path + process-environment + command-line-args noninteractive)))) + ;; FIXME: Handle varaliases! + (let ((v (symbol-value s))) + (push `(set-default + ',s + ,(cond + ;; FIXME: (Correct) hack to avoid + ;; unprintable objects. + ((eq s 'undo-auto--undoably-changed-buffers) nil) + ;; FIXME: Incorrect hack to avoid + ;; unprintable objects. + ((eq s 'advertised-signature-table) + (make-hash-table :test 'eq :weakness 'key)) + ((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) + (push `(defvar ,s) cmds))) + (when (symbol-plist s) + (push `(setplist ',s ',(symbol-plist s)) cmds)) + (when (get s 'face-defface-spec) + (push s faces)) + (if (get s 'internal--cs-args) + (push s coding-systems)) + (when (and (coding-system-p s) + (not (eq s (car (coding-system-aliases s))))) + (push (cons s (car (coding-system-aliases s))) + coding-system-aliases)) + (if (get s 'internal--charset-args) + (push s charsets) + (when (and (charsetp s) + (not (eq s (get-charset-property s :name)))) + (push (cons s (get-charset-property s :name)) + charset-aliases)))) + obarray) + (message "Dumping into dumped.elc...printing...") + (with-current-buffer (generate-new-buffer "dumped.elc") + (insert ";ELC\^W\^@\^@\^@\n;;; Compiled\n;;; in Emacs version " + emacs-version "\n") + (let ((print-circle t) + (print-gensym t) + (print-quoted t) + (print-level nil) + (print-length nil) + (print-escape-newlines t) + (standard-output (current-buffer))) + (print `(progn . ,cmds)) + (terpri) + (print `(let ((css ',charsets)) + (dotimes (i 3) + (dolist (cs (prog1 css (setq css nil))) + ;; (message "Defining charset %S..." cs) + (condition-case nil + (progn + (apply #'define-charset-internal + cs (get cs 'internal--charset-args)) + ;; (message "Defining charset %S...done" cs) + ) + (error + ;; (message "Defining charset %S...postponed" + ;; cs) + (push cs css))))))) + (terpri) + (print `(dolist (cs ',charset-aliases) + (define-charset-alias (car cs) (cdr cs)))) + (terpri) + (print `(let ((css ',coding-systems)) + (dotimes (i 3) + (dolist (cs (prog1 css (setq css nil))) + ;; (message "Defining coding-system %S..." cs) + (condition-case nil + (progn + (apply #'define-coding-system-internal + cs (get cs 'internal--cs-args)) + ;; (message "Defining coding-system %S...done" cs) + ) + (error + ;; (message "Defining coding-system %S...postponed" + ;; cs) + (push cs css))))))) + (print `(dolist (f ',faces) + (face-spec-set f (get f 'face-defface-spec) + 'face-defface-spec))) + (terpri) + (print `(dolist (cs ',coding-system-aliases) + (define-coding-system-alias (car cs) (cdr cs)))) + (terpri) + (print `(progn + ;; (message "Done preloading!") + ;; (message "custom-delayed-init-variables = %S" + ;; custom-delayed-init-variables) + ;; (message "Running top-level = %S" top-level) + (setq debug-on-error t) + (use-global-map global-map) + (eval top-level) + ;; (message "top-level done!?") + )) + (terpri)) + (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, diff --git a/src/coding.c b/src/coding.c index 9f709be..a677758 100644 --- a/src/coding.c +++ b/src/coding.c @@ -10326,8 +10326,9 @@ usage: (define-coding-system-internal ...) */) CHECK_NUMBER_CAR (reg_usage); CHECK_NUMBER_CDR (reg_usage); - request = Fcopy_sequence (args[coding_arg_iso2022_request]); - for (tail = request; CONSP (tail); tail = XCDR (tail)) + request = Qnil; + for (tail = args[coding_arg_iso2022_request]; + CONSP (tail); tail = XCDR (tail)) { int id; Lisp_Object tmp1; @@ -10339,7 +10340,8 @@ usage: (define-coding-system-internal ...) */) CHECK_NATNUM_CDR (val); if (XINT (XCDR (val)) >= 4) error ("Invalid graphic register number: %"pI"d", XINT (XCDR (val))); - XSETCAR (val, make_number (id)); + request = Fcons (Fcons (make_number (id), XCDR (val)), + request); } flags = args[coding_arg_iso2022_flags]; diff --git a/src/emacs.c b/src/emacs.c index 2480dfc..bdf3742 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -1593,9 +1593,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #endif Vtop_level = list2 (Qload, build_unibyte_string (file)); } - /* Unless next switch is -nl, load "loadup.el" first thing. */ - if (! no_loadup) - Vtop_level = list2 (Qload, build_string ("loadup.el")); + else if (! no_loadup) + /* Unless next switch is -nl, load "loadup.el" first thing. */ + Vtop_level = list2 (Qload, build_string ("../src/dumped.elc")); } /* Set up for profiling. This is known to work on FreeBSD,