Skip to content

[UpdateDoublesSketch] More heap allocation than 0.8.3 #398

@hezhangjian

Description

@hezhangjian

Hi, I noticed that there's more heap allocation than 0.8.3. Below is the detail test data.

3.2.0

@Slf4j
@State(Scope.Benchmark)
public class UpdateDoubleSketchDemo {

    private final UpdateDoublesSketch doublesSketch = new DoublesSketchBuilder().build();

    @Benchmark
    public void benchMark() {
        doublesSketch.update(RandomUtil.randomDouble());
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(UpdateDoubleSketchDemo.class.getSimpleName())
                .addProfiler(GCProfiler.class)
                .forks(1)
                .build();

        new Runner(opt).run();
    }

}

it shows

Benchmark                                                       Mode  Cnt         Score        Error   Units
UpdateDoubleSketchDemo.benchMark                               thrpt    5  21829812.630 ± 832954.814   ops/s
UpdateDoubleSketchDemo.benchMark:·gc.alloc.rate                thrpt    5         8.269 ±      0.322  MB/sec
UpdateDoubleSketchDemo.benchMark:·gc.alloc.rate.norm           thrpt    5         0.417 ±      0.001    B/op
UpdateDoubleSketchDemo.benchMark:·gc.churn.G1_Eden_Space       thrpt    5        11.421 ±     98.334  MB/sec
UpdateDoubleSketchDemo.benchMark:·gc.churn.G1_Eden_Space.norm  thrpt    5         0.575 ±      4.953    B/op
UpdateDoubleSketchDemo.benchMark:·gc.count                     thrpt    5         1.000               counts
UpdateDoubleSketchDemo.benchMark:·gc.time                      thrpt    5         2.000                   ms

0.8.3

@State(Scope.Benchmark)
public class UpdateDoubleSketchDemo {

    private final DoublesSketch doublesSketch = new DoublesSketchBuilder().build();

    @Benchmark
    public void benchMark() {
        doublesSketch.update(RandomUtil.randomDouble());
    }

    public static void main(String[] args) throws RunnerException {
        Options opt = new OptionsBuilder()
                .include(UpdateDoubleSketchDemo.class.getSimpleName())
                .addProfiler(GCProfiler.class)
                .forks(1)
                .build();

        new Runner(opt).run();
    }

}

it shows

Benchmark                                              Mode  Cnt         Score        Error   Units
UpdateDoubleSketchDemo.benchMark                      thrpt    5  22132550.180 ± 695427.053   ops/s
UpdateDoubleSketchDemo.benchMark:·gc.alloc.rate       thrpt    5         0.001 ±      0.004  MB/sec
UpdateDoubleSketchDemo.benchMark:·gc.alloc.rate.norm  thrpt    5        ≈ 10⁻⁵                 B/op
UpdateDoubleSketchDemo.benchMark:·gc.count            thrpt    5           ≈ 0               counts

And the RandomUtil

public class RandomUtil {

    private static final Random RANDOM = new Random();

    public static double randomDouble() {
        return 0 + 500 * RANDOM.nextDouble();
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions