Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
27 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
I uploaded new changesets to
http://code.google.com/p/pharo/issues/detail?id=3002


I tested applying them in Pharo-Core-#12159
and then updating an image after that.

After update:
MCMethodDefinition cachedDefinitions size is 18668

But image don't feels slow.

As a side note, i recommend to review the MC caching mechanism towards
avoiding putting so much load
on finalization process (such as scanning 18k entries to find dead objects).

This is actually the purpose of new finalization scheme:
- it allows to avoid scanning whole weak dictionary in order to get
rid of expired associations.

I'm already implemented a variant of self-cleaning weak dictionary for Magma,
which using new finalization scheme, and avoids scanning huge number
of entries to discover few of them,
which became garbage.


--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Levente Uzonyi-2
On Fri, 1 Oct 2010, Igor Stasenko wrote:

> I uploaded new changesets to
> http://code.google.com/p/pharo/issues/detail?id=3002
>
>
> I tested applying them in Pharo-Core-#12159
> and then updating an image after that.
>
> After update:
> MCMethodDefinition cachedDefinitions size is 18668
>
> But image don't feels slow.
>
> As a side note, i recommend to review the MC caching mechanism towards
> avoiding putting so much load
> on finalization process (such as scanning 18k entries to find dead objects).
>
> This is actually the purpose of new finalization scheme:
> - it allows to avoid scanning whole weak dictionary in order to get
> rid of expired associations.

WeakKeyDictionaries shouldn't be added to the finalization process at all.
In the current case there's no finalization action at all, so it's
totally pointless IMO. And these dictionaries are not thread-safe, so bad
things can happen if they are registered with the finalization process.

>
> I'm already implemented a variant of self-cleaning weak dictionary for Magma,
> which using new finalization scheme, and avoids scanning huge number
> of entries to discover few of them,
> which became garbage.

Squeak's WeakKeyDictionaries are self cleaning, though the there's no
guarantee that finalization action is performed when the key is GC'd.


Levente

>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 1 October 2010 20:05, Levente Uzonyi <[hidden email]> wrote:

> On Fri, 1 Oct 2010, Igor Stasenko wrote:
>
>> I uploaded new changesets to
>> http://code.google.com/p/pharo/issues/detail?id=3002
>>
>>
>> I tested applying them in Pharo-Core-#12159
>> and then updating an image after that.
>>
>> After update:
>> MCMethodDefinition cachedDefinitions size is 18668
>>
>> But image don't feels slow.
>>
>> As a side note, i recommend to review the MC caching mechanism towards
>> avoiding putting so much load
>> on finalization process (such as scanning 18k entries to find dead
>> objects).
>>
>> This is actually the purpose of new finalization scheme:
>> - it allows to avoid scanning whole weak dictionary in order to get
>> rid of expired associations.
>
> WeakKeyDictionaries shouldn't be added to the finalization process at all.
> In the current case there's no finalization action at all, so it's totally
> pointless IMO. And these dictionaries are not thread-safe, so bad things can
> happen if they are registered with the finalization process.
>

well..then we probably should fix this:

MCMethodDefinition>>cachedDefinitions
        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.
WeakArray addWeakDependent: Definitions].
        ^ Definitions

>>
>> I'm already implemented a variant of self-cleaning weak dictionary for
>> Magma,
>> which using new finalization scheme, and avoids scanning huge number
>> of entries to discover few of them,
>> which became garbage.
>
> Squeak's WeakKeyDictionaries are self cleaning, though the there's no
> guarantee that finalization action is performed when the key is GC'd.
>
it depends how badly you need to keep things clean as soon as its possible :)

It is really not necessary to add cachedDefinitions to weakdependets
and check them each time after GC.
In case of MC, i think a dead-keys cleanup should be triggered only
after package loading/unloading,
but not during each GC.

>
> Levente
>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
Here the simple fix for it.





--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

mc-cache-fix.1.cs (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
I just tried to update image with old cache:
[ Utilities updateFromServer] timeToRun
397707

and without it:
[ Utilities updateFromServer] timeToRun
347708


397707 / 347708 asFloat  1.143795943722894

so, roughly 14% of CPU time (about 50 seconds) wasted on scanning the
cache at each GC.

Of course this measure a bit dirty, because there a network activity involved .


On 1 October 2010 20:33, Igor Stasenko <[hidden email]> wrote:

> Here the simple fix for it.
>
>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Stéphane Ducasse
In reply to this post by Igor Stasenko
Hi igor

do you understand why the previous definition was

cachedDefinitions
        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.  WeakArray addWeakDependent: Definitions].
        ^ Definitions

Stef

On Oct 1, 2010, at 7:34 PM, Igor Stasenko wrote:

> Here the simple fix for it.
>
>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
> <mc-cache-fix.1.cs>_______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 2 October 2010 19:47, Stéphane Ducasse <[hidden email]> wrote:
> Hi igor
>
> do you understand why the previous definition was
>
> cachedDefinitions
>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.  WeakArray addWeakDependent: Definitions].
>        ^ Definitions
>
i don't. :)

It just a way to free memory as fast as possible.
But its really not worth spending so much CPU in order to save few
bytes of memory.

> Stef
>
> On Oct 1, 2010, at 7:34 PM, Igor Stasenko wrote:
>
>> Here the simple fix for it.
>>
>>
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>> <mc-cache-fix.1.cs>_______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Stéphane Ducasse
In reply to this post by Stéphane Ducasse

On Oct 2, 2010, at 7:01 PM, Igor Stasenko wrote:

> On 2 October 2010 19:47, Stéphane Ducasse <[hidden email]> wrote:
>> Hi igor
>>
>> do you understand why the previous definition was
>>
>> cachedDefinitions
>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.  WeakArray addWeakDependent: Definitions].
>>        ^ Definitions
>>
> i don't. :)
>
> It just a way to free memory as fast as possible.
> But its really not worth spending so much CPU in order to save few
> bytes of memory.

:)

I looked a bit at the code and it is used just so that MCDefinition flush them if they are not already GCed.
So I understand.

Stef


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Henrik Sperre Johansen
In reply to this post by Igor Stasenko
  On 02.10.2010 19:01, Igor Stasenko wrote:

> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>  wrote:
>> Hi igor
>>
>> do you understand why the previous definition was
>>
>> cachedDefinitions
>>         Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.  WeakArray addWeakDependent: Definitions].
>>         ^ Definitions
>>
> i don't. :)
>
> It just a way to free memory as fast as possible.
> But its really not worth spending so much CPU in order to save few
> bytes of memory.
Without registering the dict for finalization, the values won't ever be
removed with the current implementation.
Which can be somewhat hampering to performance once you have lots of
nil-keyed elements all stashed from index 1 and onwards after a rehash.

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 3 October 2010 03:13, Henrik Sperre Johansen
<[hidden email]> wrote:

>  On 02.10.2010 19:01, Igor Stasenko wrote:
>>
>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>  wrote:
>>>
>>> Hi igor
>>>
>>> do you understand why the previous definition was
>>>
>>> cachedDefinitions
>>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.
>>>  WeakArray addWeakDependent: Definitions].
>>>        ^ Definitions
>>>
>> i don't. :)
>>
>> It just a way to free memory as fast as possible.
>> But its really not worth spending so much CPU in order to save few
>> bytes of memory.
>
> Without registering the dict for finalization, the values won't ever be
> removed with the current implementation.

They are removed. After each package load/unload operation.
I don't see a reason to do this more often.

> Which can be somewhat hampering to performance once you have lots of
> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>
In Pharo, weak dict knows how to reuse expired associations:

at: key put: anObject
        "Set the value at key to be anObject.  If key is not found, create a new
        entry for key and set is value to anObject. Answer anObject."
        | index element |
        key isNil ifTrue:[^anObject].
        index := self scanForEmpty: key.
       
        "There should always be room."
        index = 0 ifTrue: [ self error: 'No space left in dictionary' ].
       
        element := array at: index.
        element == nil
                ifTrue: [self atNewIndex: index put: (WeakKeyAssociation key: key
value: anObject)]
                ifFalse: [
                        element expired ifTrue: [ tally := tally + 1].
                        element key: key.
                        element value: anObject.
                        self fullCheck.
                ].
        ^ anObject

> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Henrik Sperre Johansen
  On 03.10.2010 05:47, Igor Stasenko wrote:

> On 3 October 2010 03:13, Henrik Sperre Johansen
> <[hidden email]>  wrote:
>>   On 02.10.2010 19:01, Igor Stasenko wrote:
>>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>   wrote:
>>>> Hi igor
>>>>
>>>> do you understand why the previous definition was
>>>>
>>>> cachedDefinitions
>>>>         Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.
>>>>   WeakArray addWeakDependent: Definitions].
>>>>         ^ Definitions
>>>>
>>> i don't. :)
>>>
>>> It just a way to free memory as fast as possible.
>>> But its really not worth spending so much CPU in order to save few
>>> bytes of memory.
>> Without registering the dict for finalization, the values won't ever be
>> removed with the current implementation.
> They are removed. After each package load/unload operation.
> I don't see a reason to do this more often.
If they are removed explicitly, then yes. But then again, if that's the
case, why use a weak dictionary in the first place?
>> Which can be somewhat hampering to performance once you have lots of
>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>
> In Pharo, weak dict knows how to reuse expired associations:
>
And when do they expire? Only when they are either finalized, or removed
explicitly.
So if you do neither, they will stay indefinately without being
removed/reused.

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 3 October 2010 12:36, Henrik Sperre Johansen
<[hidden email]> wrote:

>  On 03.10.2010 05:47, Igor Stasenko wrote:
>>
>> On 3 October 2010 03:13, Henrik Sperre Johansen
>> <[hidden email]>  wrote:
>>>
>>>  On 02.10.2010 19:01, Igor Stasenko wrote:
>>>>
>>>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>>  wrote:
>>>>>
>>>>> Hi igor
>>>>>
>>>>> do you understand why the previous definition was
>>>>>
>>>>> cachedDefinitions
>>>>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary
>>>>> new.
>>>>>  WeakArray addWeakDependent: Definitions].
>>>>>        ^ Definitions
>>>>>
>>>> i don't. :)
>>>>
>>>> It just a way to free memory as fast as possible.
>>>> But its really not worth spending so much CPU in order to save few
>>>> bytes of memory.
>>>
>>> Without registering the dict for finalization, the values won't ever be
>>> removed with the current implementation.
>>
>> They are removed. After each package load/unload operation.
>> I don't see a reason to do this more often.
>
> If they are removed explicitly, then yes. But then again, if that's the
> case, why use a weak dictionary in the first place?

i don't know much about MC to tell for sure.

>>>
>>> Which can be somewhat hampering to performance once you have lots of
>>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>>
>> In Pharo, weak dict knows how to reuse expired associations:
>>
> And when do they expire? Only when they are either finalized, or removed
> explicitly.
> So if you do neither, they will stay indefinately without being
> removed/reused.

no. they expiring when key become nil.

>
> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Henrik Sperre Johansen
  On 03.10.2010 11:59, Igor Stasenko wrote:

> On 3 October 2010 12:36, Henrik Sperre Johansen
> <[hidden email]>  wrote:
>>   On 03.10.2010 05:47, Igor Stasenko wrote:
>>> On 3 October 2010 03:13, Henrik Sperre Johansen
>>> <[hidden email]>    wrote:
>>>>   On 02.10.2010 19:01, Igor Stasenko wrote:
>>>>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>>>   wrote:
>>>>>> Hi igor
>>>>>>
>>>>>> do you understand why the previous definition was
>>>>>>
>>>>>> cachedDefinitions
>>>>>>         Definitions ifNil: [Definitions := WeakIdentityKeyDictionary
>>>>>> new.
>>>>>>   WeakArray addWeakDependent: Definitions].
>>>>>>         ^ Definitions
>>>>>>
>>>>> i don't. :)
>>>>>
>>>>> It just a way to free memory as fast as possible.
>>>>> But its really not worth spending so much CPU in order to save few
>>>>> bytes of memory.
>>>> Without registering the dict for finalization, the values won't ever be
>>>> removed with the current implementation.
>>> They are removed. After each package load/unload operation.
>>> I don't see a reason to do this more often.
>> If they are removed explicitly, then yes. But then again, if that's the
>> case, why use a weak dictionary in the first place?
> i don't know much about MC to tell for sure.
>
>>>> Which can be somewhat hampering to performance once you have lots of
>>>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>>>
>>> In Pharo, weak dict knows how to reuse expired associations:
>>>
>> And when do they expire? Only when they are either finalized, or removed
>> explicitly.
>> So if you do neither, they will stay indefinately without being
>> removed/reused.
> no. they expiring when key become nil.
>
You'd think so, yes.
However, see implementor of WeakKeyAssociation>>#expired, and senders of
#expire.

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Chris Muller-3
In reply to this post by Igor Stasenko
And this is why I had that #isTimeToClean (90-second timer) hack in
the MaDictionary's...

On Sat, Oct 2, 2010 at 12:01 PM, Igor Stasenko <[hidden email]> wrote:

> On 2 October 2010 19:47, Stéphane Ducasse <[hidden email]> wrote:
>> Hi igor
>>
>> do you understand why the previous definition was
>>
>> cachedDefinitions
>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary new.  WeakArray addWeakDependent: Definitions].
>>        ^ Definitions
>>
> i don't. :)
>
> It just a way to free memory as fast as possible.
> But its really not worth spending so much CPU in order to save few
> bytes of memory.
>
>> Stef
>>
>> On Oct 1, 2010, at 7:34 PM, Igor Stasenko wrote:
>>
>>> Here the simple fix for it.
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Best regards,
>>> Igor Stasenko AKA sig.
>>> <mc-cache-fix.1.cs>_______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
In reply to this post by Henrik Sperre Johansen
On 3 October 2010 13:03, Henrik Sperre Johansen
<[hidden email]> wrote:

>  On 03.10.2010 11:59, Igor Stasenko wrote:
>>
>> On 3 October 2010 12:36, Henrik Sperre Johansen
>> <[hidden email]>  wrote:
>>>
>>>  On 03.10.2010 05:47, Igor Stasenko wrote:
>>>>
>>>> On 3 October 2010 03:13, Henrik Sperre Johansen
>>>> <[hidden email]>    wrote:
>>>>>
>>>>>  On 02.10.2010 19:01, Igor Stasenko wrote:
>>>>>>
>>>>>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>>>>  wrote:
>>>>>>>
>>>>>>> Hi igor
>>>>>>>
>>>>>>> do you understand why the previous definition was
>>>>>>>
>>>>>>> cachedDefinitions
>>>>>>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary
>>>>>>> new.
>>>>>>>  WeakArray addWeakDependent: Definitions].
>>>>>>>        ^ Definitions
>>>>>>>
>>>>>> i don't. :)
>>>>>>
>>>>>> It just a way to free memory as fast as possible.
>>>>>> But its really not worth spending so much CPU in order to save few
>>>>>> bytes of memory.
>>>>>
>>>>> Without registering the dict for finalization, the values won't ever be
>>>>> removed with the current implementation.
>>>>
>>>> They are removed. After each package load/unload operation.
>>>> I don't see a reason to do this more often.
>>>
>>> If they are removed explicitly, then yes. But then again, if that's the
>>> case, why use a weak dictionary in the first place?
>>
>> i don't know much about MC to tell for sure.
>>
>>>>> Which can be somewhat hampering to performance once you have lots of
>>>>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>>>>
>>>> In Pharo, weak dict knows how to reuse expired associations:
>>>>
>>> And when do they expire? Only when they are either finalized, or removed
>>> explicitly.
>>> So if you do neither, they will stay indefinately without being
>>> removed/reused.
>>
>> no. they expiring when key become nil.
>>
> You'd think so, yes.
> However, see implementor of WeakKeyAssociation>>#expired, and senders of
> #expire.
>

Oh, you are right. They are not reused unless marked as expired
(associatin's value == association).
But concerning speed, then my benchmark should show an opposite results. :)

cache holding a pairs of:
compiledmethod -> MCMethodDefinitions.

Compiled methods usually gone when you either recompiling class or
removing it from system.
This is why i put #finalizeValues after package loading/unloading.
But if you think it worth adding it into some other places, then tell me where.
Still, putting it into FinalizationDependents is bad idea.

> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Stéphane Ducasse
In reply to this post by Henrik Sperre Johansen
so let us know in the bug entry what is the conclusion :)


> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>>>>>  wrote:
>>>>>>>>
>>>>>>>> Hi igor
>>>>>>>>
>>>>>>>> do you understand why the previous definition was
>>>>>>>>
>>>>>>>> cachedDefinitions
>>>>>>>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary
>>>>>>>> new.
>>>>>>>>  WeakArray addWeakDependent: Definitions].
>>>>>>>>        ^ Definitions
>>>>>>>>
>>>>>>> i don't. :)
>>>>>>>
>>>>>>> It just a way to free memory as fast as possible.
>>>>>>> But its really not worth spending so much CPU in order to save few
>>>>>>> bytes of memory.
>>>>>>
>>>>>> Without registering the dict for finalization, the values won't ever be
>>>>>> removed with the current implementation.
>>>>>
>>>>> They are removed. After each package load/unload operation.
>>>>> I don't see a reason to do this more often.
>>>>
>>>> If they are removed explicitly, then yes. But then again, if that's the
>>>> case, why use a weak dictionary in the first place?
>>>
>>> i don't know much about MC to tell for sure.
>>>
>>>>>> Which can be somewhat hampering to performance once you have lots of
>>>>>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>>>>>
>>>>> In Pharo, weak dict knows how to reuse expired associations:
>>>>>
>>>> And when do they expire? Only when they are either finalized, or removed
>>>> explicitly.
>>>> So if you do neither, they will stay indefinately without being
>>>> removed/reused.
>>>
>>> no. they expiring when key become nil.
>>>
>> You'd think so, yes.
>> However, see implementor of WeakKeyAssociation>>#expired, and senders of
>> #expire.
>>
>
> Oh, you are right. They are not reused unless marked as expired
> (associatin's value == association).
> But concerning speed, then my benchmark should show an opposite results. :)
>
> cache holding a pairs of:
> compiledmethod -> MCMethodDefinitions.
>
> Compiled methods usually gone when you either recompiling class or
> removing it from system.
> This is why i put #finalizeValues after package loading/unloading.
> But if you think it worth adding it into some other places, then tell me where.
> Still, putting it into FinalizationDependents is bad idea.
>
>> Cheers,
>> Henry
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 4 October 2010 22:09, Stéphane Ducasse <[hidden email]> wrote:
> so let us know in the bug entry what is the conclusion :)
>

I think someone should verify my benchmarks i.e.

[ self loadsomething ] timeToRun

before and after patch.

And conclusion is better be written by Henrik, because he's having
concerns about speed,
while i don't. :)

>
>> On 2 October 2010 19:47, Stéphane Ducasse<[hidden email]>
>>>>>>>>  wrote:
>>>>>>>>>
>>>>>>>>> Hi igor
>>>>>>>>>
>>>>>>>>> do you understand why the previous definition was
>>>>>>>>>
>>>>>>>>> cachedDefinitions
>>>>>>>>>        Definitions ifNil: [Definitions := WeakIdentityKeyDictionary
>>>>>>>>> new.
>>>>>>>>>  WeakArray addWeakDependent: Definitions].
>>>>>>>>>        ^ Definitions
>>>>>>>>>
>>>>>>>> i don't. :)
>>>>>>>>
>>>>>>>> It just a way to free memory as fast as possible.
>>>>>>>> But its really not worth spending so much CPU in order to save few
>>>>>>>> bytes of memory.
>>>>>>>
>>>>>>> Without registering the dict for finalization, the values won't ever be
>>>>>>> removed with the current implementation.
>>>>>>
>>>>>> They are removed. After each package load/unload operation.
>>>>>> I don't see a reason to do this more often.
>>>>>
>>>>> If they are removed explicitly, then yes. But then again, if that's the
>>>>> case, why use a weak dictionary in the first place?
>>>>
>>>> i don't know much about MC to tell for sure.
>>>>
>>>>>>> Which can be somewhat hampering to performance once you have lots of
>>>>>>> nil-keyed elements all stashed from index 1 and onwards after a rehash.
>>>>>>>
>>>>>> In Pharo, weak dict knows how to reuse expired associations:
>>>>>>
>>>>> And when do they expire? Only when they are either finalized, or removed
>>>>> explicitly.
>>>>> So if you do neither, they will stay indefinately without being
>>>>> removed/reused.
>>>>
>>>> no. they expiring when key become nil.
>>>>
>>> You'd think so, yes.
>>> However, see implementor of WeakKeyAssociation>>#expired, and senders of
>>> #expire.
>>>
>>
>> Oh, you are right. They are not reused unless marked as expired
>> (associatin's value == association).
>> But concerning speed, then my benchmark should show an opposite results. :)
>>
>> cache holding a pairs of:
>> compiledmethod -> MCMethodDefinitions.
>>
>> Compiled methods usually gone when you either recompiling class or
>> removing it from system.
>> This is why i put #finalizeValues after package loading/unloading.
>> But if you think it worth adding it into some other places, then tell me where.
>> Still, putting it into FinalizationDependents is bad idea.
>>
>>> Cheers,
>>> Henry
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Henrik Sperre Johansen
  On 04.10.2010 21:47, Igor Stasenko wrote:

> On 4 October 2010 22:09, Stéphane Ducasse<[hidden email]>  wrote:
>> so let us know in the bug entry what is the conclusion :)
>>
> I think someone should verify my benchmarks i.e.
>
> [ self loadsomething ] timeToRun
>
> before and after patch.
>
> And conclusion is better be written by Henrik, because he's having
> concerns about speed,
> while i don't. :)
I already have:

http://code.google.com/p/pharo/issues/detail?id=1628#c13

Cheers,
Henry

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Igor Stasenko
On 4 October 2010 22:51, Henrik Sperre Johansen
<[hidden email]> wrote:

>  On 04.10.2010 21:47, Igor Stasenko wrote:
>>
>> On 4 October 2010 22:09, Stéphane Ducasse<[hidden email]>
>>  wrote:
>>>
>>> so let us know in the bug entry what is the conclusion :)
>>>
>> I think someone should verify my benchmarks i.e.
>>
>> [ self loadsomething ] timeToRun
>>
>> before and after patch.
>>
>> And conclusion is better be written by Henrik, because he's having
>> concerns about speed,
>> while i don't. :)
>
> I already have:
>
> http://code.google.com/p/pharo/issues/detail?id=1628#c13
>
emm.. wait.
WeakKeyDict should not delete associations with nil-ed keys
automatically, because otherwise
you won't be able to use it in weak finalization scheme.

There is two distinct use cases of weak-key dicts:
a) for weak finalization
b) for attaching some extra info(value) per object(key), which can be
automatically discarded once object become garbage

so, while in case (b) you can mercilessly kill/reuse associations with
nil keys, once they discovered
in case (a) you should preserve them until there is explicit request
from outside to finalize values.

The need in (a), apparently prohibits from using (b) in most efficient manner.
So, i think, the solution would be to introduce a specialized weak-key
dicts, which can work much better for (b).

> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: Another fixes to finalization (was Re: [update 1.2] #12161 - #12172)

Levente Uzonyi-2
On Mon, 4 Oct 2010, Igor Stasenko wrote:

> On 4 October 2010 22:51, Henrik Sperre Johansen
<[hidden email]> wrote:

>  On 04.10.2010 21:47, Igor Stasenko wrote:
>>
>> On 4 October 2010 22:09, Stéphane Ducasse<[hidden email]>
>>  wrote:
>>>
>>> so let us know in the bug entry what is the conclusion :)
>>>
>> I think someone should verify my benchmarks i.e.
>>
>> [ self loadsomething ] timeToRun
>>
>> before and after patch.
>>
>> And conclusion is better be written by Henrik, because he's having
>> concerns about speed,
>> while i don't. :)
>
> I already have:
>
> http://code.google.com/p/pharo/issues/detail?id=1628#c13
>
emm.. wait.
WeakKeyDict should not delete associations with nil-ed keys
automatically, because otherwise
you won't be able to use it in weak finalization scheme.

There is two distinct use cases of weak-key dicts:
a) for weak finalization
b) for attaching some extra info(value) per object(key), which can be
automatically discarded once object become garbage

so, while in case (b) you can mercilessly kill/reuse associations with
nil keys, once they discovered
in case (a) you should preserve them until there is explicit request
from outside to finalize values.

The need in (a), apparently prohibits from using (b) in most efficient manner.
So, i think, the solution would be to introduce a specialized weak-key
dicts, which can work much better for (b).


Squeak's implementation works well in both cases.


Levente

> Cheers,
> Henry
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project



--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
12