* bug#69706: 30.0.50; sort.c, unnecessary GC marking
@ 2024-03-10 8:45 Gerd Möllmann
2024-03-10 10:38 ` Eli Zaretskii
0 siblings, 1 reply; 8+ messages in thread
From: Gerd Möllmann @ 2024-03-10 8:45 UTC (permalink / raw)
To: 69706
sort.c uses record_unwind_protect_mark to let GC mark some objects in
its merge_state structure, while GC marks the specpdl stack.
This is
- unnecessary because all the objects that are currrently extra
protected by merge_markmem, are already seen by the GC, because these
are the objects being sorted, which are protected in the usual way
(marking the control stack, ...)
- costs GC time
- complicates the code
I therefore suggest removing this, including the removal of
record_unwind_protect_mark and the mark function pointer in union
specbinding (sort.c is the only user).
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 8:45 bug#69706: 30.0.50; sort.c, unnecessary GC marking Gerd Möllmann
@ 2024-03-10 10:38 ` Eli Zaretskii
2024-03-10 10:51 ` Gerd Möllmann
2024-03-10 11:16 ` Mattias Engdegård
0 siblings, 2 replies; 8+ messages in thread
From: Eli Zaretskii @ 2024-03-10 10:38 UTC (permalink / raw)
To: Gerd Möllmann, Mattias Engdegård, Stefan Monnier; +Cc: 69706
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Date: Sun, 10 Mar 2024 09:45:01 +0100
>
> sort.c uses record_unwind_protect_mark to let GC mark some objects in
> its merge_state structure, while GC marks the specpdl stack.
>
> This is
>
> - unnecessary because all the objects that are currrently extra
> protected by merge_markmem, are already seen by the GC, because these
> are the objects being sorted, which are protected in the usual way
> (marking the control stack, ...)
>
> - costs GC time
>
> - complicates the code
>
> I therefore suggest removing this, including the removal of
> record_unwind_protect_mark and the mark function pointer in union
> specbinding (sort.c is the only user).
Can you show the patch, please?
Adding Stefan and Mattias to the discussion, in case they have
comments or suggestions.
Thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 10:38 ` Eli Zaretskii
@ 2024-03-10 10:51 ` Gerd Möllmann
2024-03-10 11:12 ` Eli Zaretskii
2024-03-10 11:16 ` Mattias Engdegård
1 sibling, 1 reply; 8+ messages in thread
From: Gerd Möllmann @ 2024-03-10 10:51 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Mattias Engdegård, Stefan Monnier, 69706
Eli Zaretskii <eliz@gnu.org> writes:
> Can you show the patch, please?
I haven't made one yet. Should I?
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 10:51 ` Gerd Möllmann
@ 2024-03-10 11:12 ` Eli Zaretskii
0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2024-03-10 11:12 UTC (permalink / raw)
To: Gerd Möllmann; +Cc: mattiase, monnier, 69706
> From: Gerd Möllmann <gerd.moellmann@gmail.com>
> Cc: Mattias Engdegård <mattiase@acm.org>, Stefan Monnier
> <monnier@iro.umontreal.ca>, 69706@debbugs.gnu.org
> Date: Sun, 10 Mar 2024 11:51:41 +0100
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > Can you show the patch, please?
>
> I haven't made one yet. Should I?
I think so, yes.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 10:38 ` Eli Zaretskii
2024-03-10 10:51 ` Gerd Möllmann
@ 2024-03-10 11:16 ` Mattias Engdegård
2024-03-10 11:29 ` Gerd Möllmann
1 sibling, 1 reply; 8+ messages in thread
From: Mattias Engdegård @ 2024-03-10 11:16 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Gerd Möllmann, Stefan Monnier, 69706
>> sort.c uses record_unwind_protect_mark to let GC mark some objects in
>> its merge_state structure, while GC marks the specpdl stack.
>>
>> This is
>>
>> - unnecessary because all the objects that are currrently extra
>> protected by merge_markmem, are already seen by the GC, because these
>> are the objects being sorted, which are protected in the usual way
>> (marking the control stack, ...)
Thank you Gerd, but I don't think we can guarantee that those objects are present anywhere else -- the original vector is being mutated by the algorithm, after all.
In addition, I have Grand Plans (well, some kind of plans) for an improvement to the sorting code that will likely require record_unwind_protect_mark or an equivalent facility. A new bug will be opened about that.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 11:16 ` Mattias Engdegård
@ 2024-03-10 11:29 ` Gerd Möllmann
2024-03-10 13:38 ` Mattias Engdegård
0 siblings, 1 reply; 8+ messages in thread
From: Gerd Möllmann @ 2024-03-10 11:29 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: Eli Zaretskii, Stefan Monnier, 69706
Mattias Engdegård <mattias.engdegard@gmail.com> writes:
>>> sort.c uses record_unwind_protect_mark to let GC mark some objects in
>>> its merge_state structure, while GC marks the specpdl stack.
>>>
>>> This is
>>>
>>> - unnecessary because all the objects that are currrently extra
>>> protected by merge_markmem, are already seen by the GC, because these
>>> are the objects being sorted, which are protected in the usual way
>>> (marking the control stack, ...)
>
> Thank you Gerd, but I don't think we can guarantee that those objects
> are present anywhere else -- the original vector is being mutated by
> the algorithm, after all.
You nean sort.c is removing objects temporarily from the vector, so that
they are not reachable from any other root, especially from the control
stack? Could be, the code is a bit hard to follow.
OTOH, I think it would not be too hard to make such objects reachanble
from control stack...
> In addition, I have Grand Plans (well, some kind of plans) for an
> improvement to the sorting code that will likely require
> record_unwind_protect_mark or an equivalent facility. A new bug will
> be opened about that.
Please make it easy for a concurrent, mostly-copying GC, use the stack
;-).
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 11:29 ` Gerd Möllmann
@ 2024-03-10 13:38 ` Mattias Engdegård
2024-03-10 14:01 ` Gerd Möllmann
0 siblings, 1 reply; 8+ messages in thread
From: Mattias Engdegård @ 2024-03-10 13:38 UTC (permalink / raw)
To: Gerd Möllmann; +Cc: Eli Zaretskii, Stefan Monnier, 69706
10 mars 2024 kl. 12.29 skrev Gerd Möllmann <gerd.moellmann@gmail.com>:
> You nean sort.c is removing objects temporarily from the vector, so that
> they are not reachable from any other root, especially from the control
> stack? Could be, the code is a bit hard to follow.
The comment in cleanup_mem is explicit about this:
> /* If we have an exception while merging, some of the list elements
> might only live in temp storage; we copy everything remaining in
> the temp storage back into the original list. This ensures that
> the original list has all of the original elements, although
> their order is unpredictable. */
> Please make it easy for a concurrent, mostly-copying GC, use the stack
We can't use the C stack for allocations of arbitrary size, unfortunately.
Furthermore, we currently make the (correct) assumption that explicit xmalloc/xfree for temporary storage is faster than allocating a Lisp vector in most places. If a new GC shrinks the performance gap sufficiently, then we could reconsider that.
See bug#69709 for the new `sort` plan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* bug#69706: 30.0.50; sort.c, unnecessary GC marking
2024-03-10 13:38 ` Mattias Engdegård
@ 2024-03-10 14:01 ` Gerd Möllmann
0 siblings, 0 replies; 8+ messages in thread
From: Gerd Möllmann @ 2024-03-10 14:01 UTC (permalink / raw)
To: Mattias Engdegård; +Cc: Eli Zaretskii, Stefan Monnier, 69706
Mattias Engdegård <mattias.engdegard@gmail.com> writes:
> 10 mars 2024 kl. 12.29 skrev Gerd Möllmann <gerd.moellmann@gmail.com>:
>
>> You nean sort.c is removing objects temporarily from the vector, so that
>> they are not reachable from any other root, especially from the control
>> stack? Could be, the code is a bit hard to follow.
>
> The comment in cleanup_mem is explicit about this:
Ok, too bad :-(
>
>> /* If we have an exception while merging, some of the list elements
>> might only live in temp storage; we copy everything remaining in
>> the temp storage back into the original list. This ensures that
>> the original list has all of the original elements, although
>> their order is unpredictable. */
>
>
>> Please make it easy for a concurrent, mostly-copying GC, use the stack
>
> We can't use the C stack for allocations of arbitrary size,
> unfortunately.
That goes without saying. I was more thinking about having a Lisp_Vector
on the stack, maybe in the state, which is already on the stack.
> Furthermore, we currently make the (correct) assumption that explicit
> xmalloc/xfree for temporary storage is faster than allocating a Lisp
> vector in most places. If a new GC shrinks the performance gap
> sufficiently, then we could reconsider that.
>
> See bug#69709 for the new `sort` plan.
Thanks, if I find the time, I'll take a look.
So, I guess I should close this.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-03-10 14:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-10 8:45 bug#69706: 30.0.50; sort.c, unnecessary GC marking Gerd Möllmann
2024-03-10 10:38 ` Eli Zaretskii
2024-03-10 10:51 ` Gerd Möllmann
2024-03-10 11:12 ` Eli Zaretskii
2024-03-10 11:16 ` Mattias Engdegård
2024-03-10 11:29 ` Gerd Möllmann
2024-03-10 13:38 ` Mattias Engdegård
2024-03-10 14:01 ` Gerd Möllmann
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).