Skip to content

Commit

Permalink
Do not disable BackgroundCompilation in benchmarks (#9646)
Browse files Browse the repository at this point in the history
* Do not disable BackgroundCompilation in benchmarks

* Increase warmup for Table sorting benchmarks.

#9470
  • Loading branch information
Akirathan authored Apr 8, 2024
1 parent 1c4a927 commit 7850312
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.io.IOAccess;

public class Utils {
public final class Utils {
private Utils() {}

public static Context.Builder createDefaultContextBuilder() {
return Context.newBuilder()
.allowExperimentalOptions(true)
Expand All @@ -28,6 +30,10 @@ public static Context.Builder createDefaultContextBuilder() {
.option(RuntimeOptions.LOG_LEVEL, Level.WARNING.getName())
.option(RuntimeOptions.DISABLE_IR_CACHES, "true")
.option(RuntimeOptions.STRICT_ERRORS, "true")
.option("engine.CompilationFailureAction", "Print")
// MultiTier = false does not affect the peak performance, and the graphs generated from
// that are easier to inspect in IGV.
.option("engine.MultiTier", "false")
.logHandler(System.err)
.allowIO(IOAccess.ALL)
.allowAllAccess(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class ArrayProxyBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();
var code =
"""
import Standard.Base.Data.Vector.Vector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.enso.compiler.benchmarks.Utils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -201,7 +202,7 @@ public class AtomBenchmarks {

@Setup
public void initializeBenchmarks(BenchmarkParams params) throws IOException {
this.context = SrcUtil.newContextBuilder().build();
this.context = Utils.createDefaultContextBuilder().build();

var millionElemListMethod = mainMethod(context, "millionElementList", MILLION_ELEMENT_LIST);
this.millionElementsList = millionElemListMethod.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class CallableBenchmarks {

@Setup
public void initializeBenchmarks(BenchmarkParams params) {
this.context = SrcUtil.newContextBuilder().build();
this.context = org.enso.compiler.benchmarks.Utils.createDefaultContextBuilder().build();

this.sumTCOfromCall = Utils.getMainMethod(context, SUM_TCO_FROM_CALL_CODE);
this.sumTCOmethodCall = Utils.getMainMethod(context, SUM_TCO_METHOD_CALL_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.enso.compiler.benchmarks.Utils;
import org.enso.polyglot.MethodNames.Module;
import org.graalvm.polyglot.Value;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -53,7 +54,7 @@ public class EqualsBenchmarks {
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var random = new Random(42);

var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();

var benchmarkName = SrcUtil.findName(params);
var codeBuilder =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.enso.compiler.benchmarks.Utils;
import org.enso.polyglot.MethodNames.Module;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class IfVsCaseBenchmarks {
@Setup
public void initializeBench(BenchmarkParams params) throws IOException {
OutputStream out = new ByteArrayOutputStream();
ctx = SrcUtil.newContextBuilder().out(out).err(out).build();
ctx = Utils.createDefaultContextBuilder().out(out).err(out).build();

var code =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class ListBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();

var benchmarkName = SrcUtil.findName(params);
var code =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class NamedDefaultedArgumentBenchmarks {

@Setup
public void initializeBenchmarks(BenchmarkParams params) {
this.context = SrcUtil.newContextBuilder().build();
this.context = org.enso.compiler.benchmarks.Utils.createDefaultContextBuilder().build();
this.sumTCOWithNamedArguments = Utils.getMainMethod(context, SUM_TCO_WITH_NAMED_ARGUMENTS_CODE);
this.sumTCOWithDefaultedArguments =
Utils.getMainMethod(context, SUM_TCO_WITH_DEFAULTED_ARGUMENTS_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.enso.compiler.benchmarks.Utils;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -32,7 +33,7 @@ public class NestedPatternCompilationBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
ctx = SrcUtil.newContextBuilder().build();
ctx = Utils.createDefaultContextBuilder().build();
benchmarkName = SrcUtil.findName(params);
code =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ State.put Number (acc + n)

@Setup
public void initializeBenchmarks(BenchmarkParams params) {
this.context = SrcUtil.newContextBuilder().build();
this.context = org.enso.compiler.benchmarks.Utils.createDefaultContextBuilder().build();

this.sumTCO = Utils.getMainMethod(context, SUM_TCO_CODE);
this.sumTCOWithEval = Utils.getMainMethod(context, SUM_TCO_WITH_EVAL_CODE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.logging.Level;
import org.enso.polyglot.MethodNames.Module;
import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
import org.graalvm.polyglot.io.IOAccess;
import org.openjdk.jmh.infra.BenchmarkParams;

final class SrcUtil {
Expand Down Expand Up @@ -49,24 +45,4 @@ static Value getMainMethod(Context context, String benchmarkName, String code)
}
return main;
}

/**
* Typical builder suitable for benchmarking.
*
* @return preconfigured builder to use as a base for benchmarking
*/
static Context.Builder newContextBuilder() {
return Context.newBuilder()
.allowExperimentalOptions(true)
.option(RuntimeOptions.LOG_LEVEL, Level.WARNING.getName())
.logHandler(System.err)
.allowIO(IOAccess.ALL)
.allowAllAccess(true)
.option("engine.MultiTier", "false")
.option("engine.BackgroundCompilation", "false")
.option("engine.CompilationFailureAction", "Print")
.option(
RuntimeOptions.LANGUAGE_HOME_OVERRIDE,
Paths.get("../../distribution/component").toFile().getAbsolutePath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand Down Expand Up @@ -29,7 +30,7 @@ public class StringBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();
var code =
"""
from Standard.Base import all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.enso.compiler.benchmarks.Utils;
import org.enso.polyglot.MethodNames.Module;
import org.graalvm.polyglot.Value;
import org.openjdk.jmh.annotations.Benchmark;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class TypePatternBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();
var code =
"""
from Standard.Base import Integer, Vector, Any, Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.AbstractList;
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;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class VectorBenchmarks {

@Setup
public void initializeBenchmark(BenchmarkParams params) throws Exception {
var ctx = SrcUtil.newContextBuilder().build();
var ctx = Utils.createDefaultContextBuilder().build();
var benchmarkName = SrcUtil.findName(params);
var code =
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.enso.compiler.benchmarks.Utils;
import org.enso.polyglot.MethodNames;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
Expand Down Expand Up @@ -67,7 +68,7 @@ private GeneratedVector generateRandomVector(

@Setup
public void initializeBench(BenchmarkParams params) throws IOException {
this.ctx = SrcUtil.newContextBuilder().build();
this.ctx = Utils.createDefaultContextBuilder().build();
var random = new Random(42);

benchmarkName = SrcUtil.findName(params);
Expand Down
7 changes: 4 additions & 3 deletions test/Benchmarks/src/Table/Sorting.enso
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ type Data
Data.Value create_ints create_dates create_objects create_ints_table create_dates_table create_objects_table


options = Bench.options . set_warmup (Bench.phase_conf 1 7) . set_measure (Bench.phase_conf 1 3)
table_sort_opts = Bench.options . set_warmup (Bench.phase_conf 5 8) . set_measure (Bench.phase_conf 5 3)
vec_sort_opts = Bench.options . set_warmup (Bench.phase_conf 1 7) . set_measure (Bench.phase_conf 1 3)


collect_benches = Bench.build builder->
data = Data.create

builder.group "Table_Sorting" options group_builder->
builder.group "Table_Sorting" table_sort_opts group_builder->
group_builder.specify "table_order_by_ints" <|
data.ints_table.order_by [Sort_Column.Index 0]

Expand All @@ -58,7 +59,7 @@ collect_benches = Bench.build builder->
group_builder.specify "table_order_by_objects" <|
data.objects_table.order_by [Sort_Column.Index 0]

builder.group "Vector_Sorting" options group_builder->
builder.group "Vector_Sorting" vec_sort_opts group_builder->
group_builder.specify "vector_sort_ints" <|
data.ints.sort

Expand Down

0 comments on commit 7850312

Please sign in to comment.