[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gcmh 49db303 02/32: initial implementation
From: |
Andrea Corallo |
Subject: |
[elpa] externals/gcmh 49db303 02/32: initial implementation |
Date: |
Mon, 16 Nov 2020 17:32:03 -0500 (EST) |
branch: externals/gcmh
commit 49db3037587b92e1c7e993875d4c609c42df0c36
Author: Andrea Corallo <andrea_corallo@yahoo.it>
Commit: Andrea Corallo <andrea_corallo@yahoo.it>
initial implementation
---
gcmh.el | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
diff --git a/gcmh.el b/gcmh.el
index 4500e82..69daea1 100644
--- a/gcmh.el
+++ b/gcmh.el
@@ -1 +1,98 @@
;;; gcmh.el --- the Garbage Collector Magic Hack -*- lexical-binding:t -*-
+
+;; Copyright (C) 2019 Andrea Corallo
+
+;; Maintainer: andrea_corallo@yahoo.it
+;; Package: gcmh
+;; Homepage: https://gitlab.com/koral/gcmh
+;; Version: 0.1
+;; Package-Requires:
+;; Keywords: garbage collector, garbage collection
+
+;; This file is not part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; Enforce an optimized Garbage Collection strategy to minimize GC
+;; interference with the user activity.
+;; A more detailed explanation of the rationale behind this can be found at
+;; http://akrl.sdf.org/
+
+;;; Code:
+
+(defcustom gcmh-low-cons-threshold gc-cons-threshold
+ "High cons gc threshold.
+This is the gc threshold used while in idle. Default value is \
+`gc-cons-threshold'"
+ :group 'gcmh
+ :type 'number)
+
+(defcustom gcmh-high-cons-threshold #x40000000
+ "High cons gc threshold.
+This should be set to a value that makes GC unlikely but does not make the OS \
+paging."
+ :group 'gcmh
+ :type 'number)
+
+(defcustom gcmh-verbose nil
+ "If t print a message into when garbage collecting."
+ :group 'gcmh
+ :type 'boolean)
+
+(defvar gcmh-timer nil
+ "Idle timer set for trigering GC.")
+
+(defmacro gcmh-time (&rest body)
+ "Measure and return the time it takes to evaluate BODY."
+ `(let ((time (current-time)))
+ ,@body
+ (float-time (time-since time))))
+
+(defun gcmh-set-high-threshold ()
+ "Set the high gc thereshold.
+This is to be used with the `pre-command-hook'."
+ (setq gc-cons-threshold gcmh-high-cons-threshold))
+
+;;;###autoload
+(define-minor-mode gcmh-mode
+ "Minor mode tweak Garbage Colelction strategy."
+ :lighter " GCMH"
+ :global t
+ (cond
+ (gcmh-mode
+ (progn
+ (setq gc-cons-threshold gcmh-high-cons-threshold)
+ ;; Print a message when garbage collecting
+ (setq garbage-collection-messages gcmh-verbose)
+ ;; When idle for 15sec run the GC no matter what.
+ (unless gcmh-timer
+ (setq gcmh-timer
+ (run-with-idle-timer 15 t
+ (lambda ()
+ (if gcmh-verbose
+ (message "Garbage Collector has run
for %.06fsec"
+ (gcmh-time (garbage-collect)))
+ (garbage-collect))
+ (setq gc-cons-threshold
gcmh-low-cons-threshold)))))
+ (add-hook 'pre-command-hook #'gcmh-set-high-threshold)))
+ (t (progn
+ (setq gc-cons-threshold gcmh-low-cons-threshold)
+ (cancel-timer gcmh-timer)
+ (setq gcmh-timer nil)
+ (remove-hook 'pre-command-hook #'gcmh-set-high-threshold)))))
+
+(provide 'gcmh)
+
+;;; gcmh.el ends here
- [elpa] branch externals/gcmh created (now 5a83e25), Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh db9eceb 01/32: initial add, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 49db303 02/32: initial implementation,
Andrea Corallo <=
- [elpa] externals/gcmh 8008009 03/32: some minor fixes, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 920bc52 05/32: better comments, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 1953d91 15/32: Merge branch 'master' into 'master', Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 5bf0ed3 16/32: Prevent duplicate idle timers being created, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh a7f8cc2 17/32: Correct minor typos, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 91cd1f7 07/32: autoload minor mode, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh e7af13d 11/32: better readme layout, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh c96bd70 12/32: update readme, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 5664cb3 14/32: Add garbage collection start message, Andrea Corallo, 2020/11/16
- [elpa] externals/gcmh 75de01e 04/32: add missing requires, Andrea Corallo, 2020/11/16