Add performance optimizations
- monitoring startup and gc times - IO, file ops, and rendering
This commit is contained in:
parent
ff386ad54e
commit
4bba7122f3
1 changed files with 123 additions and 2 deletions
125
config.org
125
config.org
|
|
@ -26,8 +26,6 @@ This configuration needs to be loaded by =init.el=. Create an =init.el= with thi
|
||||||
Early-init optimizations for faster Emacs startup.
|
Early-init optimizations for faster Emacs startup.
|
||||||
|
|
||||||
#+begin_src emacs-lisp
|
#+begin_src emacs-lisp
|
||||||
;; Garbage collection
|
|
||||||
(setq gc-cons-threshold 100000000) ; 100mb
|
|
||||||
(setq read-process-output-max (* 1024 1024)) ; 1mb
|
(setq read-process-output-max (* 1024 1024)) ; 1mb
|
||||||
|
|
||||||
;; Faster startup
|
;; Faster startup
|
||||||
|
|
@ -35,6 +33,129 @@ Early-init optimizations for faster Emacs startup.
|
||||||
(setq site-run-file nil)
|
(setq site-run-file nil)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
** Garbage Collection
|
||||||
|
The garbage collector in Emacs can significantly impact performance. We can optimize it in several ways:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Increase garbage collection threshold
|
||||||
|
;; Default is 800 kilobytes
|
||||||
|
(setq gc-cons-threshold 100000000) ; 100mb during initialization
|
||||||
|
(setq gc-cons-percentage 0.6) ; Default is 0.1
|
||||||
|
|
||||||
|
;; Reset garbage collection after initialization
|
||||||
|
(add-hook 'emacs-startup-hook
|
||||||
|
(lambda ()
|
||||||
|
(setq gc-cons-threshold 16777216 ; 16mb
|
||||||
|
gc-cons-percentage 0.1)))
|
||||||
|
|
||||||
|
;; Collect garbage when Emacs is out of focus
|
||||||
|
(add-function :after after-focus-change-function
|
||||||
|
(lambda ()
|
||||||
|
(unless (frame-focus-state)
|
||||||
|
(garbage-collect))))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** File Processing
|
||||||
|
Optimize how Emacs handles file operations and processes:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Increase amount of data read from processes
|
||||||
|
(setq read-process-output-max (* 1024 1024)) ; 1mb
|
||||||
|
|
||||||
|
;; File name handler optimization
|
||||||
|
(defvar default-file-name-handler-alist file-name-handler-alist)
|
||||||
|
(setq file-name-handler-alist nil) ; Remove handlers during startup
|
||||||
|
|
||||||
|
;; Restore file name handlers after initialization
|
||||||
|
(add-hook 'emacs-startup-hook
|
||||||
|
(lambda ()
|
||||||
|
(setq file-name-handler-alist default-file-name-handler-alist)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Startup Optimizations
|
||||||
|
Disable unnecessary features during startup:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Faster startup
|
||||||
|
(setq package-enable-at-startup nil) ; Don't load packages at startup
|
||||||
|
(setq site-run-file nil) ; Don't load site-wide runtime config
|
||||||
|
(setq frame-inhibit-implied-resize t) ; Don't resize frame during init
|
||||||
|
|
||||||
|
;; Disable UI elements early
|
||||||
|
(push '(menu-bar-lines . 0) default-frame-alist)
|
||||||
|
(push '(tool-bar-lines . 0) default-frame-alist)
|
||||||
|
(push '(vertical-scroll-bars) default-frame-alist)
|
||||||
|
|
||||||
|
;; Disable bidirectional text scanning for small performance boost
|
||||||
|
(setq-default bidi-paragraph-direction 'left-to-right)
|
||||||
|
(setq bidi-inhibit-bpa t)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** Font Performance
|
||||||
|
Optimize font rendering:
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Prevent font cache compaction during GC for potentially better performance
|
||||||
|
;; at the cost of higher memory usage
|
||||||
|
(setq inhibit-compacting-font-caches t)
|
||||||
|
;; Font rendering optimization
|
||||||
|
(setq use-default-font-for-symbols nil)
|
||||||
|
(when (functionp 'harfbuzz-font)
|
||||||
|
(setq harfbuzz-font t))
|
||||||
|
|
||||||
|
;; File operation optimization
|
||||||
|
(setq find-file-visit-truename nil) ; Don't resolve symlinks
|
||||||
|
(setq vc-follow-symlinks nil) ; Don't follow symlinks in version control
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** IO Performance
|
||||||
|
Optimize file system operations:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Lock files (handle with care)
|
||||||
|
(setq create-lockfiles nil) ; Disable lock files completely
|
||||||
|
;; OR for more granular control:
|
||||||
|
(setq lock-file-name-transforms ; Store lock files elsewhere
|
||||||
|
`((".*" ,(concat user-emacs-directory "locks/") t)))
|
||||||
|
|
||||||
|
;; Backup settings (safer alternative to disabling)
|
||||||
|
(setq backup-directory-alist ; Store backups in separate directory
|
||||||
|
`(("." . ,(concat user-emacs-directory "backups"))))
|
||||||
|
(setq backup-by-copying t) ; Always copy, don't rename
|
||||||
|
(setq delete-old-versions t) ; Clean up old backups
|
||||||
|
(setq kept-new-versions 6) ; Keep 6 newest versions
|
||||||
|
(setq kept-old-versions 2) ; Keep 2 oldest versions
|
||||||
|
|
||||||
|
;; Auto-save optimization
|
||||||
|
(setq auto-save-list-file-prefix nil) ; Disable auto-save list
|
||||||
|
(setq auto-save-default t) ; Keep auto-save itself enabled
|
||||||
|
(setq auto-save-interval 1000) ; Increase operations between auto-saves
|
||||||
|
(setq auto-save-timeout 30) ; Increase idle time before auto-save
|
||||||
|
|
||||||
|
;; Local variables handling
|
||||||
|
(setq enable-local-variables :safe) ; Only allow safe variables
|
||||||
|
(setq enable-dir-local-variables nil) ; Disable directory locals
|
||||||
|
(setq enable-local-eval nil) ; Disable local eval for security
|
||||||
|
|
||||||
|
;; Display and rendering
|
||||||
|
(setq redisplay-skip-fontification-on-input t) ; Skip fontification during typing
|
||||||
|
(setq fast-but-imprecise-scrolling t) ; Faster scrolling
|
||||||
|
(setq jit-lock-defer-time 0.05) ; Tiny delay for better responsiveness
|
||||||
|
|
||||||
|
#+end_src
|
||||||
|
** Monitoring Performance
|
||||||
|
Tools to help monitor Emacs performance:
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
;; Profile emacs startup
|
||||||
|
(add-hook 'emacs-startup-hook
|
||||||
|
(lambda ()
|
||||||
|
(message "*** Emacs loaded in %s with %d garbage collections."
|
||||||
|
(format "%.2f seconds"
|
||||||
|
(float-time
|
||||||
|
(time-subtract after-init-time before-init-time)))
|
||||||
|
gcs-done)))
|
||||||
|
#+end_src
|
||||||
|
|
||||||
* Basic UI Configuration
|
* Basic UI Configuration
|
||||||
Remove unnecessary UI elements and set basic preferences.
|
Remove unnecessary UI elements and set basic preferences.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue