all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Hash table GC
@ 2024-10-14  4:32 Anand Tamariya
  2024-10-14 14:00 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Tamariya @ 2024-10-14  4:32 UTC (permalink / raw)
  To: Emacs Devel

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

Hi,
If I've created a hash table with :weakness nil, how do I release it for GC
when it is no longer needed?

Regards,
Anand

[-- Attachment #2: Type: text/html, Size: 209 bytes --]

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

* Re: Hash table GC
  2024-10-14  4:32 Hash table GC Anand Tamariya
@ 2024-10-14 14:00 ` Eli Zaretskii
  2024-10-15  7:48   ` Anand Tamariya
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-10-14 14:00 UTC (permalink / raw)
  To: Anand Tamariya; +Cc: emacs-devel

> From: Anand Tamariya <atamariya@gmail.com>
> Date: Mon, 14 Oct 2024 10:02:24 +0530
> 
> If I've created a hash table with :weakness nil, how do I release it for GC when it is no longer needed?

Why are you asking specifically about hash-tables?  AFAIK, they are
not different from any other Lisp object in this regard.  Weakness
affects GC of the keys and values, not of the table itself, AFAIU.



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

* Re: Hash table GC
  2024-10-14 14:00 ` Eli Zaretskii
@ 2024-10-15  7:48   ` Anand Tamariya
  2024-10-15 12:33     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Anand Tamariya @ 2024-10-15  7:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

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

I'm trying to use a hash table for storing parsed CSS values. I'm seeing a
degradation in performance (memory and CPU) over a period of time. Trying
to investigate how to fix the same. Below is a minimal example:

(dotimes (i 10000)
  (let* ((a (make-hash-table :test 'equal :weakness 'key-or-value))
(j 0))
    (dolist (prop '(padding margin margin-top border
                            color background background-color display
                            width height clear
                            font font-size font-style font-weight))
      (puthash j (list prop (setq j (1+ j))) a))
    (pp a)
    ))
(Emacs 28.2 on Debian)

On Mon, Oct 14, 2024 at 7:30 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Anand Tamariya <atamariya@gmail.com>
> > Date: Mon, 14 Oct 2024 10:02:24 +0530
> >
> > If I've created a hash table with :weakness nil, how do I release it for
> GC when it is no longer needed?
>
> Why are you asking specifically about hash-tables?  AFAIK, they are
> not different from any other Lisp object in this regard.  Weakness
> affects GC of the keys and values, not of the table itself, AFAIU.
>

[-- Attachment #2: Type: text/html, Size: 1635 bytes --]

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

* Re: Hash table GC
  2024-10-15  7:48   ` Anand Tamariya
@ 2024-10-15 12:33     ` Eli Zaretskii
  2024-10-15 13:07       ` Tassilo Horn
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2024-10-15 12:33 UTC (permalink / raw)
  To: Anand Tamariya; +Cc: emacs-devel

> From: Anand Tamariya <atamariya@gmail.com>
> Date: Tue, 15 Oct 2024 13:18:10 +0530
> Cc: emacs-devel@gnu.org
> 
> I'm trying to use a hash table for storing parsed CSS values. I'm seeing a degradation in performance
> (memory and CPU) over a period of time. Trying to investigate how to fix the same. Below is a minimal
> example:
> 
> (dotimes (i 10000)
>   (let* ((a (make-hash-table :test 'equal :weakness 'key-or-value))
> (j 0))
>     (dolist (prop '(padding margin margin-top border
>                             color background background-color display
>                             width height clear
>                             font font-size font-style font-weight))
>       (puthash j (list prop (setq j (1+ j))) a))
>     (pp a)
>     ))

You are using 'key-or-value, which prevents the table from being GCed
of _either_ key or value cannot be GCed.  And your keys are symbols,
so they are not GCed.

So I think you should not use 'key-or-value if you want the table to
be GCed.  E.g., why not use t instead?



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

* Re: Hash table GC
  2024-10-15 12:33     ` Eli Zaretskii
@ 2024-10-15 13:07       ` Tassilo Horn
  0 siblings, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2024-10-15 13:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Anand Tamariya, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> (dotimes (i 10000)
>>   (let* ((a (make-hash-table :test 'equal :weakness 'key-or-value))
>> (j 0))
>>     (dolist (prop '(padding margin margin-top border
>>                             color background background-color display
>>                             width height clear
>>                             font font-size font-style font-weight))
>>       (puthash j (list prop (setq j (1+ j))) a))
>>     (pp a)
>>     ))
>
> You are using 'key-or-value, which prevents the table from being GCed
> of _either_ key or value cannot be GCed.  And your keys are symbols,
> so they are not GCed.

Really?  I would assume that in a table with :weakness 'key-or-value the
*entries* can be removed/GCed if there are no references to either the
entry's key or value.  But the whole table should still be GCed if
there's no reference to the table itself.  So in the above example, I'd
think that `a' is GC-able immediately after the `let*`.

Running the above many times doesn't seem to increase my Emacs memory
footprint so my statement feels right.

Bye,
  Tassilo



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

end of thread, other threads:[~2024-10-15 13:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14  4:32 Hash table GC Anand Tamariya
2024-10-14 14:00 ` Eli Zaretskii
2024-10-15  7:48   ` Anand Tamariya
2024-10-15 12:33     ` Eli Zaretskii
2024-10-15 13:07       ` Tassilo Horn

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.