Question about MethodDictionary in TraitedClass (methodDict/localMethodDict)
Hi, We were profiling the loading of code that uses many Traits. We saw something like this (this is a tally for `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:`): [image: Screenshot 2022-05-11 at 17.17.37.png]
From what we saw in `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:` a method is first added to `localMethodDict` and then it calls the super method that adds the selector to the `methodDict` of the actual class in `Behaviour>>addSelectorSilently:withMethod: `. Because of this we basically get an overhead as a method is added to two method dictionaries and adding a method to a MethodDictionary is slower, as it does operations like `flushCache` and `cachePragmas`.
Should the `localMethodDict` also be an instance of MethodDictionary or could it be a simple dictionary? Cheers, Andrei
On 12 May 2022, at 11:27, Andrei Chis <chisvasileandrei@gmail.com> wrote:
Hi,
We were profiling the loading of code that uses many Traits. We saw something like this (this is a tally for `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:`): <Screenshot 2022-05-11 at 17.17.37.png>
From what we saw in `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:` a method is first added to `localMethodDict` and then it calls the super method that adds the selector to the `methodDict` of the actual class in `Behaviour>>addSelectorSilently:withMethod: `. Because of this we basically get an overhead as a method is added to two method dictionaries and adding a method to a MethodDictionary is slower, as it does operations like `flushCache` and `cachePragmas`.
Should the `localMethodDict` also be an instance of MethodDictionary or could it be a simple dictionary?
I think it can be normal Dictionary: MethodDictionary we just meed where there VM executes code (for flushCache) and for lookup. The only downside is that it then uses a little bit more memory (MethodDictionary does not use associations), but that should be no problem. Marcus
On Thu, May 12, 2022 at 3:19 PM Marcus Denker <marcus.denker@inria.fr> wrote:
On 12 May 2022, at 11:27, Andrei Chis <chisvasileandrei@gmail.com> wrote:
Hi,
We were profiling the loading of code that uses many Traits. We saw something like this (this is a tally for `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:`): <Screenshot 2022-05-11 at 17.17.37.png>
From what we saw in `TraitedMetaclass>>#addAndClassifySelector:withMethod:inProtocol:` a method is first added to `localMethodDict` and then it calls the super method that adds the selector to the `methodDict` of the actual class in `Behaviour>>addSelectorSilently:withMethod: `. Because of this we basically get an overhead as a method is added to two method dictionaries and adding a method to a MethodDictionary is slower, as it does operations like `flushCache` and `cachePragmas`.
Should the `localMethodDict` also be an instance of MethodDictionary or could it be a simple dictionary?
I think it can be normal Dictionary: MethodDictionary we just meed where there VM executes code (for flushCache) and for lookup.
Ok. I can experiment with replacing it with a Dictionary and see how it goes.
The only downside is that it then uses a little bit more memory (MethodDictionary does not use associations), but that should be no problem.
Indeed that's an interesting aspect. Maybe more important for the Pharo image is memory rather than loading speed. Cheers, Andrei
Marcus
participants (2)
-
Andrei Chis -
Marcus Denker