Am Do., 26. Sept. 2024 um 20:32 Uhr schrieb Daphne Preston-Kendal <
d...@nonceword.org>:

> On 26 Sep 2024, at 20:27, Marc Nieper-Wißkirchen <marc.nie...@gmail.com>
> wrote:
>
> > Given the example of a weak hash table, when an existing association is
> updated, why do we want to add the inefficiency of replacing the whole
> ephemeron/weak pair when a simple mutation would work?
>
> I don’t accept that it would be more inefficient in all cases.


Not in all cases, sure, but in those where it would introduce unnecessary
boxing.


> Under the optimization I suggest, replacing a potentially-circular
> ephemeron with a weak pair (whose value is of a type that can’t possibly
> link back to the key) would probably be a performance win. But without
> benchmarks we are speculating here, and this has nothing to do with my
> original suggestion, which is about using them as weak boxes, not as weak
> pairs.
>

What speaks against a proper "weak pair" type?


> > Another example I have in mind is a linked list of weak pairs (say, as
> part of a cache structure) modelling a list of weak keys.
>
> Don’t you also need a strong pair to maintain the link to the next weak
> pair in that case? Otherwise, one weak pair being broken will cause the
> entire rest of the list to be lost.
>

That's why I wrote "weak pair" and not "ephemeron".  Ah, now I understand
the confusion.  I am using a "weak pair" in the sense of Chez, where the
value is retained even if the key is broken.  In any case, this is an
example of a mutable data structure where it would be inefficient to wrap
each weak box.

Reply via email to