Skip to content

Speedup Traits recompilation #19745

Open
jecisc wants to merge 6 commits into
pharo-project:Pharo14from
jecisc:kernel/trait-compilation-speedup
Open

Speedup Traits recompilation #19745
jecisc wants to merge 6 commits into
pharo-project:Pharo14from
jecisc:kernel/trait-compilation-speedup

Conversation

@jecisc

@jecisc jecisc commented May 30, 2026

Copy link
Copy Markdown
Member

Trait recompilation can become really slow if the trait is used a lot.

For example, on my machine, it takes 58seconds to add an ivar to TEntityMetalevelDependency from Moose.

Here is a step forward into speeding up this. I introduced a method #selectorsDo: on trait compositions and I used it to implement a faster #includesSelector:.

The idea of #selectorsDo: is to not create intermediate collections and to stop faster if we have a non local return.

With this change, the recompilation of TEntityMetalevelDependency dropped to around 45sec. The change is not huge, but it is better than nothing.

@jecisc

jecisc commented Jun 1, 2026

Copy link
Copy Markdown
Member Author

I have another idea to speed up the compilation.

In #rebuildMethodDictionary we ask to the trait composition the selectors to rebuild. But then, we spend time looking for the defining trait of each selector to set the trait origin property, to find the compiled method and to find the source code.

What we could do is to implement a method returning the selectors of the trait composition linked to their defining trait. Like this, we would avoid 3 lookup of the origin trait.

image

Here we can see all the senders of #memberForSelector:

But I have no idea when I'll have the time to implement this. It'll probably be for another PR. And maybe a first step could be to check only once for the defining trait in #compile:into:?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants