aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2020-12-11 13:51:07 +0100
committerLars Ingebrigtsen2020-12-11 13:51:07 +0100
commit2cba76f948f7a5d10d1b07fd0cc3b3e236d82dc5 (patch)
tree2323ed32ce55219f0783bf259218019690ba2e31
parentcda3bb3b95a6fda60d93e98e99d77fe26cfbedca (diff)
downloademacs-scratch/memrep.tar.gz
emacs-scratch/memrep.zip
Tweak symbol sizescratch/memrep
-rw-r--r--lisp/emacs-lisp/memory-report.el25
-rw-r--r--test/lisp/emacs-lisp/memory-report-tests.el10
2 files changed, 28 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index d4444ef485f..6067db10cb2 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -31,6 +31,8 @@
31(require 'subr-x) 31(require 'subr-x)
32(eval-when-compile (require 'cl-lib)) 32(eval-when-compile (require 'cl-lib))
33 33
34(defvar memory-report--type-size (make-hash-table))
35
34;;;###autoload 36;;;###autoload
35(defun memory-report () 37(defun memory-report ()
36 "Generate a report of how Emacs is using memory." 38 "Generate a report of how Emacs is using memory."
@@ -68,8 +70,6 @@
68 (memory-report--garbage-collect)) 70 (memory-report--garbage-collect))
69 (memory-report--object-size (make-hash-table :test #'eq) object)) 71 (memory-report--object-size (make-hash-table :test #'eq) object))
70 72
71(defvar memory-report--type-size (make-hash-table))
72
73(defun memory-report--size (type) 73(defun memory-report--size (type)
74 (or (gethash type memory-report--type-size) 74 (or (gethash type memory-report--type-size)
75 (gethash 'object memory-report--type-size))) 75 (gethash 'object memory-report--type-size)))
@@ -162,8 +162,12 @@
162(cl-defgeneric memory-report--object-size-1 (_counted _value) 162(cl-defgeneric memory-report--object-size-1 (_counted _value)
163 0) 163 0)
164 164
165(cl-defmethod memory-report--object-size-1 (_ (_value symbol)) 165(cl-defmethod memory-report--object-size-1 (_ (value symbol))
166 (memory-report--size 'symbol)) 166 ;; Don't count global symbols -- makes sizes of lists of symbols too
167 ;; heavey.
168 (if (intern-soft value obarray)
169 0
170 (memory-report--size 'symbol)))
167 171
168(cl-defmethod memory-report--object-size-1 (_ (_value buffer)) 172(cl-defmethod memory-report--object-size-1 (_ (_value buffer))
169 (memory-report--size 'buffer)) 173 (memory-report--size 'buffer))
@@ -171,7 +175,18 @@
171(cl-defmethod memory-report--object-size-1 (counted (value string)) 175(cl-defmethod memory-report--object-size-1 (counted (value string))
172 (+ (memory-report--size 'string) 176 (+ (memory-report--size 'string)
173 (string-bytes value) 177 (string-bytes value)
174 (memory-report--object-size counted (object-intervals value)))) 178 (memory-report--interval-size counted (object-intervals value))))
179
180(defun memory-report--interval-size (counted intervals)
181 ;; We get a list back of intervals, but only count the "inner list"
182 ;; (i.e., the actual text properties), and add the size of the
183 ;; intervals themselves.
184 (+ (* (memory-report--size 'interval) (length intervals))
185 (seq-reduce #'+ (mapcar
186 (lambda (interval)
187 (memory-report--object-size counted (nth 2 interval)))
188 intervals)
189 0)))
175 190
176(cl-defmethod memory-report--object-size-1 (counted (value list)) 191(cl-defmethod memory-report--object-size-1 (counted (value list))
177 (let ((total 0) 192 (let ((total 0)
diff --git a/test/lisp/emacs-lisp/memory-report-tests.el b/test/lisp/emacs-lisp/memory-report-tests.el
index 146800fd2e8..01bcf18423a 100644
--- a/test/lisp/emacs-lisp/memory-report-tests.el
+++ b/test/lisp/emacs-lisp/memory-report-tests.el
@@ -37,11 +37,17 @@
37 (should (equal (memory-report-object-size (cons nil nil)) 16)) 37 (should (equal (memory-report-object-size (cons nil nil)) 16))
38 (should (equal (memory-report-object-size (cons 1 2)) 16)) 38 (should (equal (memory-report-object-size (cons 1 2)) 16))
39 39
40 (should (equal (memory-report-object-size (list 1 2)) 32))
41 (should (equal (memory-report-object-size (list 1)) 16))
42
43 (should (equal (memory-report-object-size (list 'foo)) 16))
44
45 (should (equal (memory-report-object-size (vector 1 2 3 4)) 80))
46
40 (should (equal (memory-report-object-size "") 32)) 47 (should (equal (memory-report-object-size "") 32))
41 (should (equal (memory-report-object-size "a") 33)) 48 (should (equal (memory-report-object-size "a") 33))
42 (should (equal (memory-report-object-size (propertize "a" 'face 'foo)) 49 (should (equal (memory-report-object-size (propertize "a" 'face 'foo))
43 ;; Possibly? 50 81)))
44 161)))
45 51
46(provide 'memory-report-tests) 52(provide 'memory-report-tests)
47 53