all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Fix memory-report--object-size for hashtable and vectors
@ 2021-08-14 10:18 Yikai Zhao
  2021-08-14 11:46 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Yikai Zhao @ 2021-08-14 10:18 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 760 bytes --]

Hi,

I'd like to send a simple patch to fix the `memory-report--object-size' function in memory-report.el. Currently it did not give correct object size for hashtable and vector objects, this patch fixes that.

I noticed this bug because when I did `memory-report', the result items in "Largest Variables" list were unreasonably small and it did not match the "Overall Object Memory Usage". With this patch, this should be solved.

To verify this, execute the following code:

(memory-report--object-size
 (make-hash-table :test #'eq)
 ["long string that should be at least 40 bytes"])

The expected output should be a number greater than 40.

This is my first attempt to submit a patch to emacs, please let me know if there's anything missing. Thanks!


Yikai

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-memory-report-object-size-for-hashtable-and-vect.patch --]
[-- Type: text/x-patch; name="0001-Fix-memory-report-object-size-for-hashtable-and-vect.patch", Size: 1462 bytes --]

From cbec8009be8c7c49607ec3fe06fbba2178ed2f06 Mon Sep 17 00:00:00 2001
From: BlahGeek <i@blahgeek.com>
Date: Sat, 14 Aug 2021 18:01:17 +0800
Subject: [PATCH] Fix memory-report--object-size for hashtable and vectors

Previously the elements get inserted to the 'counted' table *before*
they get accounted. That operation is unnecessary because it will be
done at the beginning of `memory-report--object-size`
---
 lisp/emacs-lisp/memory-report.el | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index 1125dde405..1815deec40 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -230,7 +230,7 @@ memory-report--object-size-1
   (let ((total (+ (memory-report--size 'vector)
                   (* (memory-report--size 'object) (length value)))))
     (cl-loop for elem across value
-             do (setf (gethash elem counted) t)
+             do
              (cl-incf total (memory-report--object-size counted elem)))
     total))
 
@@ -239,8 +239,6 @@ memory-report--object-size-1
                   (* (memory-report--size 'object) (hash-table-size value)))))
     (maphash
      (lambda (key elem)
-       (setf (gethash key counted) t)
-       (setf (gethash elem counted) t)
        (cl-incf total (memory-report--object-size counted key))
        (cl-incf total (memory-report--object-size counted elem)))
      value)
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-14 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-14 10:18 [PATCH] Fix memory-report--object-size for hashtable and vectors Yikai Zhao
2021-08-14 11:46 ` Lars Ingebrigtsen
2021-08-14 15:24   ` Yikai Zhao
2021-08-14 15:32     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.