-
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
Optimize building and casting of EnsoMultiValue #11924
Draft
JaroslavTulach
wants to merge
17
commits into
develop
Choose a base branch
from
wip/jtulach/MultiType11846
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
086d024
Ensure isAllTypes is compilation constant
JaroslavTulach a33965d
Using internal MultiType to represent Type[] but with guaranteed ==
JaroslavTulach 171c799
Merge remote-tracking branch 'origin/develop' into wip/jtulach/MultiT…
JaroslavTulach 775595c
Prefer partialEvaluationConstant assert
JaroslavTulach e2760ff
Benchmarks for intersection types
JaroslavTulach 630ec62
Usage of Map & co. must be behind @TruffleBoundary
JaroslavTulach 8defcfe
Unify findInteropTypeValue
JaroslavTulach d44d30e
Inline cache to find index of a type
JaroslavTulach 7b6d364
Use EnsoMultiValue.NewNode to allocate new instances of EnsoMultiValue
JaroslavTulach bda398a
Basic specializations for NewNode
JaroslavTulach 56b24aa
Splitting the FindIndexNode and caching requests for newNode
JaroslavTulach 2dcc2c4
Just ask only for types the value 'has been cast to'
JaroslavTulach ee080a3
Provide cachedTypes as the first argument to activate the caches
JaroslavTulach 53c2222
AllOfTypesCheckNode needs cached EnsoMultiValue.NewNode to allocate E…
JaroslavTulach 9567257
Moving EnsoMultiType into outer scope
JaroslavTulach 6bfdbf9
Sum re field of a Complex object in a Vector is the base benchmark
JaroslavTulach 4dacf53
Cache dispatch on EnsoMultiValue.getDispatchId
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
...ks/src/main/java/org/enso/interpreter/bench/benchmarks/semantic/MultiValueBenchmarks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package org.enso.interpreter.bench.benchmarks.semantic; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
import java.util.function.Function; | ||
import org.enso.compiler.benchmarks.Utils; | ||
import org.graalvm.polyglot.Value; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.BenchmarkMode; | ||
import org.openjdk.jmh.annotations.Fork; | ||
import org.openjdk.jmh.annotations.Measurement; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.annotations.Warmup; | ||
import org.openjdk.jmh.infra.BenchmarkParams; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
/** | ||
* These benchmarks compare performance of {@link EnsoMultiValue}. They create a vector in a certain | ||
* configuration representing numbers and then they perform {@code sum} operation on it. | ||
*/ | ||
@BenchmarkMode(Mode.AverageTime) | ||
@Fork(1) | ||
@Warmup(iterations = 3) | ||
@Measurement(iterations = 5) | ||
@OutputTimeUnit(TimeUnit.MILLISECONDS) | ||
@State(Scope.Benchmark) | ||
public class MultiValueBenchmarks { | ||
private Value arrayOfNumbers; | ||
private Value sum; | ||
private Value self; | ||
private final long length = 100000; | ||
|
||
@Setup | ||
public void initializeBenchmark(BenchmarkParams params) throws Exception { | ||
var ctx = Utils.createDefaultContextBuilder().build(); | ||
var code = | ||
""" | ||
from Standard.Base import Vector, Float, Number, Integer | ||
|
||
type Complex | ||
private Number re:Float im:Float | ||
|
||
Complex.from (that:Number) = Complex.Number that 0 | ||
|
||
sum arr = | ||
go acc i = if i >= arr.length then acc else | ||
v = arr.at i : Float | ||
sum = acc + v | ||
@Tail_Call go sum i+1 | ||
go 0 0 | ||
|
||
|
||
make_vector type n = | ||
Vector.new n i-> | ||
r = 3 + 5*i | ||
case type of | ||
0 -> r:Integer | ||
1 -> r:Float | ||
2 -> r:Complex | ||
3 -> | ||
c = r:Complex&Float | ||
c:Float | ||
4 -> | ||
c = r:Float&Complex | ||
c:Float | ||
5 -> r:Complex&Float | ||
6 -> r:Float&Complex | ||
"""; | ||
var benchmarkName = SrcUtil.findName(params); | ||
var src = SrcUtil.source(benchmarkName, code); | ||
var module = ctx.eval(src); | ||
|
||
this.self = module.invokeMember("get_associated_type"); | ||
Function<String, Value> getMethod = (name) -> module.invokeMember("get_method", self, name); | ||
|
||
String test_builder; | ||
int type = Integer.parseInt(benchmarkName.substring(benchmarkName.length() - 1)); | ||
this.arrayOfNumbers = getMethod.apply("make_vector").execute(self, type, length); | ||
this.sum = getMethod.apply("sum"); | ||
} | ||
|
||
@Benchmark | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now the base benchmark. The results after 4dacf53 are:
still 60 times slower than it should be. |
||
public void sumOverInteger0(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverFloat1(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverComplexCast2(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverComplexFloatRecastedToFloat3(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverFloatComplexRecastedToFloat4(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverComplexAndFloat5(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
@Benchmark | ||
public void sumOverFloatAndComplex6(Blackhole matter) { | ||
performBenchmark(matter); | ||
} | ||
|
||
private void performBenchmark(Blackhole matter) throws AssertionError { | ||
var resultValue = sum.execute(self, arrayOfNumbers); | ||
if (!resultValue.fitsInLong()) { | ||
throw new AssertionError("Shall be a long: " + resultValue); | ||
} | ||
long result = resultValue.asLong(); | ||
long expectedResult = length * 3L + (5L * (length * (length - 1L) / 2L)); | ||
boolean isResultCorrect = result == expectedResult; | ||
if (!isResultCorrect) { | ||
throw new AssertionError("Expecting " + expectedResult + " but was " + result); | ||
} | ||
matter.consume(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
A dedicated benchmark for
EnsoMultiValue
instances based on the idea of ArrayProxy one. Currently the more complicated benchmarks refuse to compile and the compiler bails out. The initial results are:After 630ec62 the results are better:
and there are no bailouts. Time to really speed things up.
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.
Some speedup achieved...