Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Dec 21, 2023
2 parents 9594a45 + 281ec13 commit b601168
Show file tree
Hide file tree
Showing 124 changed files with 2,335 additions and 1,191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public class AggregatorBenchmark {
private static final int GROUPS = 5;

private static final BigArrays BIG_ARRAYS = BigArrays.NON_RECYCLING_INSTANCE; // TODO real big arrays?
private static final BlockFactory blockFactory = BlockFactory.getInstance(
new NoopCircuitBreaker("noop"),
BigArrays.NON_RECYCLING_INSTANCE
);

private static final String LONGS = "longs";
private static final String INTS = "ints";
Expand Down Expand Up @@ -446,7 +450,7 @@ private static Block dataBlock(BlockFactory blockFactory, String blockType) {
BLOCK_LENGTH
).asBlock();
case MULTIVALUED_LONGS -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
builder.beginPositionEntry();
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendLong(i);
Expand All @@ -459,15 +463,15 @@ private static Block dataBlock(BlockFactory blockFactory, String blockType) {
yield builder.build();
}
case HALF_NULL_LONGS -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendLong(i);
builder.appendNull();
}
yield builder.build();
}
case HALF_NULL_DOUBLES -> {
var builder = DoubleBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newDoubleBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendDouble(i);
builder.appendNull();
Expand Down Expand Up @@ -499,7 +503,7 @@ private static Block groupingBlock(String grouping, String blockType) {
};
return switch (grouping) {
case LONGS -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
for (int v = 0; v < valuesPerGroup; v++) {
builder.appendLong(i % GROUPS);
Expand All @@ -508,7 +512,7 @@ private static Block groupingBlock(String grouping, String blockType) {
yield builder.build();
}
case INTS -> {
var builder = IntBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newIntBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
for (int v = 0; v < valuesPerGroup; v++) {
builder.appendInt(i % GROUPS);
Expand All @@ -517,7 +521,7 @@ private static Block groupingBlock(String grouping, String blockType) {
yield builder.build();
}
case DOUBLES -> {
var builder = DoubleBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newDoubleBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
for (int v = 0; v < valuesPerGroup; v++) {
builder.appendDouble(i % GROUPS);
Expand All @@ -526,7 +530,7 @@ private static Block groupingBlock(String grouping, String blockType) {
yield builder.build();
}
case BOOLEANS -> {
BooleanBlock.Builder builder = BooleanBlock.newBlockBuilder(BLOCK_LENGTH);
BooleanBlock.Builder builder = blockFactory.newBooleanBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
for (int v = 0; v < valuesPerGroup; v++) {
builder.appendBoolean(i % 2 == 1);
Expand All @@ -535,7 +539,7 @@ private static Block groupingBlock(String grouping, String blockType) {
yield builder.build();
}
case BYTES_REFS -> {
BytesRefBlock.Builder builder = BytesRefBlock.newBlockBuilder(BLOCK_LENGTH);
BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
for (int v = 0; v < valuesPerGroup; v++) {
builder.appendBytesRef(bytesGroup(i % GROUPS));
Expand Down Expand Up @@ -582,9 +586,6 @@ private static void run(String grouping, String op, String blockType, int opCoun
}

static DriverContext driverContext() {
return new DriverContext(
BigArrays.NON_RECYCLING_INSTANCE,
BlockFactory.getInstance(new NoopCircuitBreaker("noop"), BigArrays.NON_RECYCLING_INSTANCE)
);
return new DriverContext(BigArrays.NON_RECYCLING_INSTANCE, blockFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.BooleanBlock;
import org.elasticsearch.compute.data.BooleanVector;
import org.elasticsearch.compute.data.IntBlock;
import org.elasticsearch.compute.data.LongBlock;
import org.elasticsearch.compute.data.LongVector;
import org.elasticsearch.compute.data.Page;
Expand Down Expand Up @@ -59,6 +58,12 @@
@State(Scope.Thread)
@Fork(1)
public class EvalBenchmark {
private static final BigArrays BIG_ARRAYS = BigArrays.NON_RECYCLING_INSTANCE; // TODO real big arrays?
private static final BlockFactory blockFactory = BlockFactory.getInstance(
new NoopCircuitBreaker("noop"),
BigArrays.NON_RECYCLING_INSTANCE
);

private static final int BLOCK_LENGTH = 8 * 1024;

static final DriverContext driverContext = new DriverContext(
Expand Down Expand Up @@ -207,32 +212,32 @@ private static void checkExpected(String operation, Page actual) {
private static Page page(String operation) {
return switch (operation) {
case "abs", "add", "date_trunc", "equal_to_const" -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendLong(i * 100_000);
}
yield new Page(builder.build());
}
case "long_equal_to_long" -> {
var lhs = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var rhs = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var lhs = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
var rhs = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
lhs.appendLong(i * 100_000);
rhs.appendLong(i * 100_000);
}
yield new Page(lhs.build(), rhs.build());
}
case "long_equal_to_int" -> {
var lhs = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var rhs = IntBlock.newBlockBuilder(BLOCK_LENGTH);
var lhs = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
var rhs = blockFactory.newIntBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
lhs.appendLong(i * 100_000);
rhs.appendInt(i * 100_000);
}
yield new Page(lhs.build(), rhs.build());
}
case "mv_min", "mv_min_ascending" -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
if (operation.endsWith("ascending")) {
builder.mvOrdering(Block.MvOrdering.DEDUPLICATED_AND_SORTED_ASCENDING);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.Randomness;
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.BooleanBlock;
Expand Down Expand Up @@ -43,6 +45,12 @@
@State(Scope.Thread)
@Fork(1)
public class MultivalueDedupeBenchmark {
private static final BigArrays BIG_ARRAYS = BigArrays.NON_RECYCLING_INSTANCE; // TODO real big arrays?
private static final BlockFactory blockFactory = BlockFactory.getInstance(
new NoopCircuitBreaker("noop"),
BigArrays.NON_RECYCLING_INSTANCE
);

@Param({ "BOOLEAN", "BYTES_REF", "DOUBLE", "INT", "LONG" })
private ElementType elementType;

Expand All @@ -58,7 +66,7 @@ public class MultivalueDedupeBenchmark {
public void setup() {
this.block = switch (elementType) {
case BOOLEAN -> {
BooleanBlock.Builder builder = BooleanBlock.newBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
BooleanBlock.Builder builder = blockFactory.newBooleanBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
for (int p = 0; p < AggregatorBenchmark.BLOCK_LENGTH; p++) {
List<Boolean> values = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand All @@ -77,7 +85,7 @@ public void setup() {
yield builder.build();
}
case BYTES_REF -> {
BytesRefBlock.Builder builder = BytesRefBlock.newBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
for (int p = 0; p < AggregatorBenchmark.BLOCK_LENGTH; p++) {
List<BytesRef> values = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand All @@ -96,7 +104,7 @@ public void setup() {
yield builder.build();
}
case DOUBLE -> {
DoubleBlock.Builder builder = DoubleBlock.newBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
DoubleBlock.Builder builder = blockFactory.newDoubleBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
for (int p = 0; p < AggregatorBenchmark.BLOCK_LENGTH; p++) {
List<Double> values = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand All @@ -115,7 +123,7 @@ public void setup() {
yield builder.build();
}
case INT -> {
IntBlock.Builder builder = IntBlock.newBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
IntBlock.Builder builder = blockFactory.newIntBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
for (int p = 0; p < AggregatorBenchmark.BLOCK_LENGTH; p++) {
List<Integer> values = new ArrayList<>();
for (int i = 0; i < size; i++) {
Expand All @@ -134,7 +142,7 @@ public void setup() {
yield builder.build();
}
case LONG -> {
LongBlock.Builder builder = LongBlock.newBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
LongBlock.Builder builder = blockFactory.newLongBlockBuilder(AggregatorBenchmark.BLOCK_LENGTH * (size + repeats));
for (int p = 0; p < AggregatorBenchmark.BLOCK_LENGTH; p++) {
List<Long> values = new ArrayList<>();
for (long i = 0; i < size; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.breaker.CircuitBreaker;
import org.elasticsearch.common.breaker.NoopCircuitBreaker;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.compute.data.Block;
import org.elasticsearch.compute.data.BlockFactory;
import org.elasticsearch.compute.data.BooleanBlock;
import org.elasticsearch.compute.data.BytesRefBlock;
import org.elasticsearch.compute.data.DoubleBlock;
import org.elasticsearch.compute.data.ElementType;
import org.elasticsearch.compute.data.IntBlock;
import org.elasticsearch.compute.data.LongBlock;
import org.elasticsearch.compute.data.Page;
import org.elasticsearch.compute.operator.Operator;
import org.elasticsearch.compute.operator.topn.TopNEncoder;
Expand Down Expand Up @@ -51,6 +50,12 @@
@State(Scope.Thread)
@Fork(1)
public class TopNBenchmark {
private static final BigArrays BIG_ARRAYS = BigArrays.NON_RECYCLING_INSTANCE; // TODO real big arrays?
private static final BlockFactory blockFactory = BlockFactory.getInstance(
new NoopCircuitBreaker("noop"),
BigArrays.NON_RECYCLING_INSTANCE
);

private static final int BLOCK_LENGTH = 8 * 1024;

private static final String LONGS = "longs";
Expand Down Expand Up @@ -137,35 +142,35 @@ private static Page page(String data) {
private static Block block(String data) {
return switch (data) {
case LONGS -> {
var builder = LongBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newLongBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendLong(i);
}
yield builder.build();
}
case INTS -> {
var builder = IntBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newIntBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendInt(i);
}
yield builder.build();
}
case DOUBLES -> {
var builder = DoubleBlock.newBlockBuilder(BLOCK_LENGTH);
var builder = blockFactory.newDoubleBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendDouble(i);
}
yield builder.build();
}
case BOOLEANS -> {
BooleanBlock.Builder builder = BooleanBlock.newBlockBuilder(BLOCK_LENGTH);
BooleanBlock.Builder builder = blockFactory.newBooleanBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendBoolean(i % 2 == 1);
}
yield builder.build();
}
case BYTES_REFS -> {
BytesRefBlock.Builder builder = BytesRefBlock.newBlockBuilder(BLOCK_LENGTH);
BytesRefBlock.Builder builder = blockFactory.newBytesRefBlockBuilder(BLOCK_LENGTH);
for (int i = 0; i < BLOCK_LENGTH; i++) {
builder.appendBytesRef(new BytesRef(Integer.toString(i)));
}
Expand Down
Loading

0 comments on commit b601168

Please sign in to comment.