unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Yikai Zhao" <i@blahgeek.com>
To: emacs-devel@gnu.org
Subject: [PATCH] Fix memory-report--object-size for hashtable and vectors
Date: Sat, 14 Aug 2021 18:18:13 +0800	[thread overview]
Message-ID: <67bebb91-aa22-4901-bf8a-d461c1a73454@www.fastmail.com> (raw)

[-- 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


             reply	other threads:[~2021-08-14 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-14 10:18 Yikai Zhao [this message]
2021-08-14 11:46 ` [PATCH] Fix memory-report--object-size for hashtable and vectors Lars Ingebrigtsen
2021-08-14 15:24   ` Yikai Zhao
2021-08-14 15:32     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=67bebb91-aa22-4901-bf8a-d461c1a73454@www.fastmail.com \
    --to=i@blahgeek.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).