hashgraph / hedera-block-node

New Block Node services
Apache License 2.0
21 stars 2 forks source link

(Richard's) To profile and analyse algorithmic diff between Google protobuf and Hashgraph's PBJ code #130

Open alex-kuzmin-hg opened 2 months ago

alex-kuzmin-hg commented 2 months ago

Goal: to compare performance/algorithms of Google protobuf and PBJ

To investigate, setup, run and report algorithmic diff Good starting point: https://github.com/hashgraph/pbj/blob/79ac1de7b8b706b583f89d2fe1c9d4e60743e480/pbj-integration-tests/src/jmh/java/com/hedera/pbj/intergration/jmh/ProtobufObjectBench.java#L32-L32

alex-kuzmin-hg commented 2 months ago

Got initial report, requested Eng sync to review....

alex-kuzmin-hg commented 2 months ago

pbjAlgCompare2/reports/perf_report.html

alex-kuzmin-hg commented 2 months ago

Found potential culprit:

Image

alex-kuzmin-hg commented 2 months ago
public static void main (String []args) throws Exception {
     final Blackhole blackhole = new Blackhole("Today's password is ......");
     final BenchmarkState<Everything, com.hedera.pbj.test.proto.java.Everything> state = new BenchmarkState<>();
     final EverythingBench bench = new EverythingBench();
     bench.setup(state);
     long start, end;
     start=System.currentTimeMillis();
     for (int i=0;i<1000;i++) {
        bench.writePbjByteBuffer(state,blackhole);
     }
     end=System.currentTimeMillis();
     System.out.println("PBJ runtime is:"+(end-start));

     start=end;
     for (int i=0;i<1000;i++) {
        bench.writeProtoCByteBuffer(state,blackhole);
     }
     end=System.currentTimeMillis();
     System.out.println("Google runtime is:"+(end-start));

    }

PBJ runtime is:17643 Google runtime is:6327

alex-kuzmin-hg commented 1 month ago

Related fixes: https://github.com/hashgraph/pbj/issues/283 https://github.com/hashgraph/pbj/issues/284 with that the diff is better: PBJ runtime is: 12106 Google runtime is: 11626