[squeak-dev] Undeclared -> WeakIdentityDictionary -> wrong tally -> wrong #size

Marcel Taeumel marcel.taeumel at hpi.de
Wed Feb 26 15:13:40 UTC 2020


Hi Levente.

> Instead of overriding #isEmpty in all weak subclasses, we can handle 
it in HashedCollection if we want to:

I think I will do that in 5.3rc2 because I will also add #isEmpty tests for those weak collections, which would fail otherwise. I hope that's okay with everybody. That bug in #isEmpty is a regression since (about) Squeak 5.1.

Here is a benchmark of #isEmpty for Smalltalk's bindings dictionary:

BEFORE
'134,000,000 per second. 7.47 nanoseconds per run. 0 % GC time.'
AFTER
'51,700,000 per second. 19.3 nanoseconds per run. 0 % GC time.'

Best,

Marcel
Am 26.02.2020 15:44:57 schrieb Levente Uzonyi <leves at caesar.elte.hu>:
Hi Marcel,

On Wed, 26 Feb 2020, Marcel Taeumel wrote:

> Hi Levente,
> hmm... but WeakSet does also not respond correctly to #isEmpty. Yes, there is a bug with tally calculation as you descrined. However, all weak collections can only support #maybeNotEmpty and never #isEmpty (because of the false case).

Right, my response is more related to one of the previous emails of yours.
But, weak collections can and should respond to #isEmpty by using
Collection's implementation.
However, due to the way weak references are handled, the response is not
entirely reliable. IMO, it's the sender's responsibility to take care of
the possibility of the changed state (#isEmpty returns false, but the last
element is gone before the next message is processed by the VM).
Instead of overriding #isEmpty in all weak subclasses, we can handle
it in HashedCollection if we want to:

isEmpty
"TODO: Add a nice comment here."

^array class isWeak
ifFalse: [ tally = 0 ]
ifTrue: [ super isEmpty ]


Levente

>
> Best,
> Marcel
>
> Am 26.02.2020 14:54:46 schrieb Levente Uzonyi :
>
> Hi Marcel,
>
> The cause of the problem is that unlike other weak hashed collections,
> WeakIdentityDictionary does not recalculate tally in
> #noCheckNoGrowFillFrom:. And that's a bug, because it lets tally increase
> indefinitely.
>
> The bug appears now, because before Undeclared became a
> WeakIdentityDictionary, #compact, which is part of what ReleaseBuilder
> does, would recalculate the tally via #noCheckNoGrowFillFrom:.
>
> So, even for weak hashed collections, tally should never be larger than
> the actual capacity (not #capacity, which currently implemented as array
> size is a misnomer) of the collection.
>
>
> Levente
>
> On Wed, 26 Feb 2020, marcel.taeumel wrote:
>
> > Maybe weak collections should never claim to be empty anymore after any
> > element was added to them? I would understand that since repeated calls can
> > return different results.
> >
> > Best,
> > Marcel
> >
> >
> >
> > --
> > Sent from: http://forum.world.st/Squeak-Dev-f45488.html
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200226/0b6eed95/attachment.html>


More information about the Squeak-dev mailing list