Subject: bug#75477: 31.0.50; scratch/igc: crash on the latest commit

From: Pip Cet <[email-masked]>
Date: Wed, 22 Jan 2025 21:23:17 +0000

"Ihor Radchenko" <[email-masked]> writes:

> Pip Cet <[email-masked]> writes:
>
>>>> ./src/emacs -Q --eval '(run-with-timer 1.0 1.0 (lambda () (delete-frame (make-frame))))'
>>>> ...
>
> Maybe try with menu bar enabled.
> I just casually enabled the menu bar and noticed significant slowdown of
> frame creation.
>
> Here is what perf says:
>
>     48.62%  emacs         emacs                                    [.] rootCreateProtectable
>     14.08%  emacs         emacs                                    [.] igc_destroy_root_with_start
>      3.08%  emacs         emacs                                    [.] fix_lisp_obj
>      1.52%  emacs         emacs                                    [.] dflt_scanx
>      1.05%  emacs         emacs                                    [.] assq_no_quit
>      0.98%  emacs         libc.so.6                                [.] 0x000000000017d947
>      0.83%  emacs         emacs                                    [.] set_buffer_internal_2
>      0.75%  emacs         emacs                                    [.] plist_get
>      0.68%  emacs         emacs                                    [.] get_keymap
>      0.61%  emacs         libX11.so.6.4.0                          [.] _XrmInternalStringToQuark
>      0.52%  emacs         libc.so.6                                [.] pthread_mutex_lock

Thank you.  I was kind of delaying looking at the excessive number of
roots created by GTK, but I think it's time.  I did notice GTK seemed a
lot slower, and I guess that's the reason :-)

We fixed two GTK memory leaks in bug#75636.  The effect of these memory
leaks was that a small number of roots was kept alive.  Unfortunately,
one of them contained a pointer to the entire frame, so that was kept
alive and became unfreeable, including all descendent structures.

I'm not sure we've fixed all of these bugs; I'll try putting frames in a
weak hash table and seeing whether they accumulate.

My initial attempt was to allow read-only roots to be shared: if we
found one which already contained the pointer we want, we'd reuse this.
This reduced the number of actually necessary roots, but not
sufficiently.  So we'll have to make other changes.

Thanks again for the report, and sorry this took a while.

Pip