-
Notifications
You must be signed in to change notification settings - Fork 323
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
Conversation
`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.
There was a problem hiding this 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
.
engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/IrPersistance.java
Outdated
Show resolved
Hide resolved
engine/runtime-parser/src/main/java/org/enso/compiler/core/ir/IrPersistance.java
Outdated
Show resolved
Hide resolved
engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/PassPersistance.java
Outdated
Show resolved
Hide resolved
@@ -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) |
There was a problem hiding this comment.
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.
engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/Graph.scala
Show resolved
Hide resolved
@@ -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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you.
engine/runtime-compiler/src/main/java/org/enso/compiler/pass/analyse/PassPersistance.java
Outdated
Show resolved
Hide resolved
engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/alias/Graph.scala
Show resolved
Hide resolved
Benchmarks appear to confirm the improvement https://github.com/enso-org/enso/actions/runs/8552014606
|
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
After
Checklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Scala,
Java,
and
Rust
style guides. In case you are using a language not listed above, follow the Rust style guide.