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

Invoke all Enso benchmarks via JMH #7101

Merged
merged 77 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
188d465
[WIP] Invoke Enso bench via JMH
Akirathan Jun 22, 2023
8836629
Abstract from direct call to Bench.measure
JaroslavTulach Jul 1, 2023
88fd6fb
Builder pattern to collect all benchmarks first and only then execute…
JaroslavTulach Jul 1, 2023
19a439e
Improve type ascriptions of Bench type
Akirathan Jul 7, 2023
f6dd423
[WIP] Add LibBenchRunner
Akirathan Jul 7, 2023
58c1e0d
Making the project compilable (again)
JaroslavTulach Jul 9, 2023
f5a9aae
Executed few suites from Vector/Operations.enso in JMH
JaroslavTulach Jul 9, 2023
3f37a7d
Merge remote-tracking branch 'origin/develop' into wip/akirathan/enso…
JaroslavTulach Jul 10, 2023
7c33b3a
Bench is the type, not Group
JaroslavTulach Jul 10, 2023
f70a6da
sumStatistic benchmark
JaroslavTulach Jul 10, 2023
1584357
Generate double values
JaroslavTulach Jul 10, 2023
0f41777
Add prototype of bench suites discovery
Akirathan Jul 17, 2023
9d9f328
Move LibBenchRunner to a separate project `bench-libs`
Akirathan Jul 17, 2023
0ee38df
Get rid of IRUtils.scala
Akirathan Jul 18, 2023
3ec89ef
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 19, 2023
733338d
Add SpecCollector
Akirathan Jul 20, 2023
5b543ef
LibBenchRunner prints help
Akirathan Jul 20, 2023
1f916e6
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 20, 2023
40a2ad7
LibBenchRunner can list benchmarks
Akirathan Jul 20, 2023
65051a4
Fix Operations.enso to provide specs and not to run them
Akirathan Jul 20, 2023
d5b41f3
Add simple annotation processor
Akirathan Jul 24, 2023
1adad1a
Move bench-libs to std-bits/benchmarks
Akirathan Jul 24, 2023
85c3b96
Integrate annotation processor into bench-libs
Akirathan Jul 24, 2023
5339233
Add truffle and runtime to annotation processor's class path
Akirathan Jul 25, 2023
a9cdd19
BenchProcessor creates JMH sources for all benchmarks
Akirathan Jul 26, 2023
906cc4d
Put generated code into src_managed directory
Akirathan Jul 26, 2023
8f3d761
Remove benchmark discovery code from LibBenchRunner
Akirathan Jul 26, 2023
179949e
Do not use generate package name for generated sources
Akirathan Jul 27, 2023
df82640
Incorporate bench and benchOnly commands in bench-libs project
Akirathan Jul 27, 2023
6ec55f9
Move LibBenchRunner under src/bench from src/main
Akirathan Jul 27, 2023
954e96f
Benchmark/run/javaOptions gets fullClasspath
Akirathan Jul 27, 2023
18e313a
Generate source into Compile/sourceManaged.
Akirathan Jul 27, 2023
4e9afc2
Use fully qualified module names in BenchProcessor
Akirathan Jul 27, 2023
45d1143
Add ability to attach debugger to the annotation processors.
Akirathan Jul 27, 2023
a124a0b
Add the benchmarks documentation
Akirathan Jul 27, 2023
8b6b96d
Discard spurious warnings from javac for generated sources
Akirathan Jul 27, 2023
16d2f56
Remove some temporary logging
Akirathan Jul 27, 2023
ad538e8
Fail annotation processing properly instead of throwing exceptions
Akirathan Jul 27, 2023
dc09d02
Fix SourceVersion warning
Akirathan Jul 27, 2023
60f2372
Catch exception, not throwable
Akirathan Jul 27, 2023
4888e45
cosmetics
Akirathan Jul 27, 2023
82b14c8
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Jul 27, 2023
95e6dea
Easier way to debug the runtime/benchOnly command
JaroslavTulach Jul 28, 2023
df99383
Restrict dependencies scopes
Akirathan Jul 28, 2023
8683d37
Merge branch 'origin/wip/akirathan/enso-bench-jmh' of github.com:enso…
Akirathan Jul 28, 2023
00e6cf3
Restructure debugging docs, reformat.
Akirathan Jul 28, 2023
62f3480
Remove meso benchmark terminology
Akirathan Jul 28, 2023
80564b0
Remove unecessary method from BenchSUiteWrapper
Akirathan Jul 28, 2023
2e57598
Some refactoring.
Akirathan Jul 28, 2023
f6bdc67
Move bench-processor from std-bits to lib/scala/bench-processor
Akirathan Jul 28, 2023
5001012
Add Benchmark runner code to bench-processor
Akirathan Jul 28, 2023
882ae8a
Delete unused benchmark code
Akirathan Jul 28, 2023
53373b7
Distinct.enso benchmark uses the new bench builder API
Akirathan Jul 28, 2023
81353d2
Main module of test/Benchmarks collects all bench specs
Akirathan Jul 28, 2023
1d389d9
Fix jakarta.xml dependency
Akirathan Jul 28, 2023
c19b53c
Add module-discovery parameters to GenerateBenchSources annotation
Akirathan Jul 28, 2023
c5ec01e
Add tests for SpecCollector
Akirathan Aug 1, 2023
9b34546
BenchProcessor supports new module-discovery parameters
Akirathan Aug 1, 2023
8bad812
Some improvements of bench-libs SBT project.
Akirathan Aug 1, 2023
2f409fb
Unify report collecting
Akirathan Aug 1, 2023
30bb9f0
Add Utils class
Akirathan Aug 1, 2023
d3e6a87
Add some tests
Akirathan Aug 1, 2023
7df60c5
No star import in Scala sources in project
Akirathan Aug 2, 2023
6676b8c
--no-limit-modules is not a hardcoded, but a documentted constant in …
Akirathan Aug 2, 2023
60899de
Filter out spurious warning messages from javac
Akirathan Aug 2, 2023
97a0036
Reformat bench-libs project in sbt - group settings by the configurat…
Akirathan Aug 2, 2023
f562284
Generated source does not contain absolute paths
Akirathan Aug 2, 2023
ea5315f
Rename `bench-libs` sbt project to `std-benchmarks`.
Akirathan Aug 2, 2023
ed1909d
In std-benchmarks project, withDebug command works the same as in run…
Akirathan Aug 2, 2023
f5e9715
Add some docs
Akirathan Aug 3, 2023
2664ded
Remove --no-limit-modules
Akirathan Aug 3, 2023
08fa60b
fmt docs
Akirathan Aug 3, 2023
495e6e6
Add some docs
Akirathan Aug 3, 2023
939e8fb
Minor fixes in the docs
Akirathan Aug 3, 2023
701183e
Merge branch 'develop' into wip/akirathan/enso-bench-jmh
Akirathan Aug 4, 2023
11e0a12
Revert "Easier way to debug the runtime/benchOnly command"
Akirathan Aug 7, 2023
7141b08
fmt docs
Akirathan Aug 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Akirathan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.enso.interpreter.bench.benchmarks.meso;

import java.io.ByteArrayOutputStream;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
import org.enso.compiler.core.IR;
import org.enso.compiler.core.IR$;
import org.graalvm.polyglot.Context;
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;

@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@Warmup(iterations = 3)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
public class VectorOperations {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = Context.newBuilder()
.allowExperimentalOptions(true)
.allowIO(true)
.allowAllAccess(true)
.logHandler(new ByteArrayOutputStream())
.option(
"enso.languageHomeOverride",
Paths.get("../../distribution/component").toFile().getAbsolutePath()
).build();

String benchMeasureRedef = """
type Bench
measure : Any -> Text -> Integer -> Integer -> Nothing
measure ~act label iter_size num_iters =
...
""";
}

private void collectBenchMeasureMethodCalls() {
new IR.Error.ImportExport.ModuleDoesNotExist("bla");
}

@Benchmark
public void benchmark(Blackhole blackhole) {

}
}
Akirathan marked this conversation as resolved.
Show resolved Hide resolved
Akirathan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from Standard.Base import all
import Standard.Base.Runtime.State
import Standard.Base

from Standard.Test import Bench

import project.Vector.Utils

polyglot java import java.util.Random as Java_Random

## Bench Utilities ============================================================

vector_size = 1000000
iter_size = 100
num_iterations = 10

# The Benchmarks ==============================================================

bench =
random_vec = Utils.make_random_vec vector_size
random_vec_2 = Utils.make_random_vec 100000
random_gen = Java_Random.new 123456

Bench.measure (Base.Vector.new vector_size i->i) "New Vector" iter_size num_iterations
Bench.measure (Base.Vector.new vector_size _->42) "New Constant" iter_size num_iterations
Bench.measure (Base.Vector.new vector_size _->random_gen.nextLong) "New Random" iter_size num_iterations
Bench.measure (Base.Vector.fill vector_size 42) "Fill Constant" iter_size num_iterations
Bench.measure (Base.Vector.fill vector_size random_gen.nextLong) "Fill Random (constant)" iter_size num_iterations
Bench.measure (random_vec + [1]) "Append Single" iter_size num_iterations
Bench.measure (random_vec + random_vec_2) "Append Large" iter_size num_iterations
Bench.measure (random_vec.reduce (+)) "Sum" iter_size num_iterations
Bench.measure ((random_vec.drop (First 20)).reduce (+)) "Drop First 20 and Sum" iter_size num_iterations
Bench.measure ((random_vec.drop (Last 20)).reduce (+)) "Drop Last 20 and Sum" iter_size num_iterations
Bench.measure (random_vec.filter (x -> x % 3 == 1)) "Filter" iter_size num_iterations
Bench.measure (random_vec.filter_with_index (i-> x-> (i+x) % 3 == 1)) "Filter With Index" iter_size num_iterations

Bench.measure (random_vec . map (x -> x + random_gen.nextLong) . filter (x -> x % 3 == 1)) "Map & Filter" iter_size num_iterations
Bench.measure (random_vec.partition (x -> x % 3 == 1)) "Partition" iter_size num_iterations
Bench.measure (random_vec.partition_with_index (i-> x-> (i+x) % 3 == 1)) "Partition With Index" iter_size num_iterations

stateful_fun x =
s = State.get Number
State.put s+x
Bench.measure (State.run Number 0 <| random_vec.each stateful_fun) "Each" iter_size num_iterations

main = bench
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.enso.interpreter.bench

import org.enso.compiler.core.IR

object IRUtils {
Akirathan marked this conversation as resolved.
Show resolved Hide resolved
private def collectBenchCalls(ir: IR.Module): List[BenchCall] = {
val methods = ir.bindings.collect { case m : IR.Module.Scope.Definition.Method => m }
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved

for (method <- methods) {
method.body.preorder.flatMap(ir => {
ir match {
case application: IR.Application.Prefix =>
application.function match {
case IR.Name.Literal("measure", true, _, _, _) =>
application.arguments.head match {
case IR.CallArgument.Specified(_, value, _, _, _) =>
value match {
case IR.Name.Literal("Bench", _, _, _, _) =>
Some(new BenchCall(application))
case _ => None
}
}
case _ => None
}
}
})
}

}

private class BenchCall(
val call: IR.Application.Prefix
) {
val args: List[IR.CallArgument.Specified] = call.arguments.collect { case s : IR.CallArgument.Specified => s }
val location: IR.IdentifiedLocation = call.location.get
assert(args.length == 5)
assert(args.head.value.asInstanceOf[IR.Name.Literal].name == "Bench")
val action: IR.Expression = args(1).value
val title: String = {
args(2).value match {
case lit: IR.Literal.Text => lit.text
case unexpected => throw new IllegalStateException(s"Unexpected bench title IR: ${unexpected}")
}
}
}
}
Loading