Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf of Graph.Scope.scopeFor hotspot #9620

Merged
merged 5 commits into from
Apr 4, 2024

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Apr 3, 2024

Pull Request Description

scopeFor appears to be a hotspot of the compiler. By choosing a more suitable data structure that indexes on the occurrence's id we seem to gain about 25% on some benchmarks. Quick win.

Related to #9235.

Important Notes

Local benchmark runs of org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars
Before

[info] # Warmup Iteration   1: 61.638 ms/op
[info] # Warmup Iteration   2: 49.224 ms/op
[info] # Warmup Iteration   3: 47.341 ms/op
[info] # Warmup Iteration   4: 46.946 ms/op
[info] # Warmup Iteration   5: 46.901 ms/op
[info] # Warmup Iteration   6: 49.536 ms/op
[info] Iteration   1: 50.438 ms/op
[info] Iteration   2: 47.326 ms/op
[info] Iteration   3: 46.917 ms/op
[info] Iteration   4: 45.824 ms/op

After

[info] # Warmup Iteration   1: 86.493 ms/op
[info] # Warmup Iteration   2: 36.084 ms/op
[info] # Warmup Iteration   3: 32.588 ms/op
[info] # Warmup Iteration   4: 33.895 ms/op
[info] # Warmup Iteration   5: 31.986 ms/op
[info] # Warmup Iteration   6: 31.236 ms/op
[info] Iteration   1: 31.258 ms/op
[info] Iteration   2: 31.673 ms/op
[info] Iteration   3: 30.931 ms/op
[info] Iteration   4: 30.902 ms/op

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.

`scopeFor` appears to be a hotspot of the compiler. By choosing a more
suitable data structure that indexes on the occurrence's id we seem to
gain about 25% on some benchmarks.
@hubertp hubertp added the CI: No changelog needed Do not require a changelog entry for this PR. label Apr 3, 2024
Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to change the persistance of Graph.Scope and remove persistance for java.lang.Integer.

@@ -456,7 +462,7 @@ object Graph {
* @return the occurrence for `id`, if it exists
*/
def getOccurrence(id: Graph.Id): Option[Occurrence] = {
occurrences.find(o => o.id == id)
occurrences.get(id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this shall be faster.

@hubertp hubertp requested a review from JaroslavTulach April 4, 2024 08:55
@@ -145,7 +150,7 @@ protected Graph.Scope readObject(Input in) throws IOException {
@SuppressWarnings("unchecked")
protected void writeObject(Graph.Scope obj, Output out) throws IOException {
out.writeInline(scala.collection.immutable.List.class, obj.childScopes());
out.writeObject(obj.occurrences());
out.writeObject(obj.occurrences().values().toSet());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Apr 4, 2024
@hubertp
Copy link
Collaborator Author

hubertp commented Apr 4, 2024

Benchmarks appear to confirm the improvement https://github.com/enso-org/enso/actions/runs/8552014606

GitHub
Hybrid visual and textual functional programming. Contribute to enso-org/enso development by creating an account on GitHub.

@mergify mergify bot merged commit a82a429 into develop Apr 4, 2024
35 of 37 checks passed
@mergify mergify bot deleted the wip/hubert/9235-alias-analysis-hotspots-hunt branch April 4, 2024 15:26
@enso-bot enso-bot bot mentioned this pull request Apr 5, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants