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

Analyze and improve the performance of AliasAnalysis compiler pass #9235

Open
Akirathan opened this issue Mar 1, 2024 · 6 comments
Open

Comments

@Akirathan
Copy link
Member

Compiler benchmarks were added in #9158.

The most appropriate benchmark for measuring alias analysis compiler pass is org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars. Run it with:

sbt:> runtime-benchmarks benchOnly org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars

Note that you can fine-tune benchmark-related options with, for example,

sbt:runtime-benchmarks> run -wi 7 -i 2 org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars

(This increases the number of warmup iterations).
See https://github.com/enso-org/enso/blob/develop/docs/infrastructure/benchmarks.md#running-the-benchmarks

The following picture from VisualVM CPU profiler shows that the vast majority of time is spent in AliasAnalysis:
image

@JaroslavTulach
Copy link
Member

Unless there is some low hanging fruit we might use this opportunity to rewrite AliasAnalysis again from scratch:

mergify bot pushed a commit that referenced this issue Apr 4, 2024
`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
```
@hubertp
Copy link
Collaborator

hubertp commented Jul 8, 2024

This likely seems obsolete. I'm not seeing much time spent in AliasAnalysis phase anymore.

@Akirathan
Copy link
Member Author

This likely seems obsolete. I'm not seeing much time spent in AliasAnalysis phase anymore.

@hubertp You mean you are not seeing much time spent in AliasAnalysis when loading a user's project in the IDE, right?The org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars benchmark should still be dominated by AliasAnalysis. If the overhead of AliasAnalysis compared to the overall time spent in compilation is minimal, then we can make this a low-prio issue.

@JaroslavTulach
Copy link
Member

This likely seems obsolete. I'm not seeing much time spent in AliasAnalysis phase anymore.

Related: The AliasAnalysis is causing slowness even when being loaded from caches.

@JaroslavTulach
Copy link
Member

If the overhead of AliasAnalysis compared to the overall time spent in compilation is minimal, then we can make this a low-prio issue.

AliasAnalysis still occupies 40% of the benchmark:

sbt:enso> runtime-benchmarks/benchOnly org.enso.compiler.benchmarks.module.ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars
org.enso.compiler.pass.analyse.AliasAnalysis$.runModule ()	7,789 ms (40.2%)	7,789 ms (40.2%)

@Akirathan
Copy link
Member Author

AliasAnalysis still occupies 40% of the benchmark:

@JaroslavTulach This is expected in this benchmark. This benchmark compiles a method that has a lot of local variables and so, we expect the alias analysis to take a lot of time. That is fine - this is an artificial benchmark that tries to measure the performance of AliasAnalysis. The important question is: "In an average user workflow project, how much time is spent in AliasAnalysis?"

To answer the question myself, I would say that this issue is important. As the ManyLocalVarsBenchmark.longMethodWithLotOfLocalVars kind of resembles the real user project (a single main method with a lot of local variables).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

3 participants