Powerspace / scala-openrtb

Scala OpenRTB tools used at @Powerspace
https://powerspace.com
Apache License 2.0
23 stars 8 forks source link

Prototype jsoniter decoding #37

Open valdo404 opened 5 years ago

valdo404 commented 5 years ago

Instead of relying on circe try jsoniter for fun and profit https://plokhotnyuk.github.io/jsoniter-scala/

plokhotnyuk commented 5 years ago

Here is derivation of codec that parses and serializes a bid request from OpenRTB 2.5.

Here is an example, provided by @atais, for a custom codec which extracts the message part that can be optionally encoded as a JSON string.

Please also check results of OpenRTBReading and OpenRTBWriting benchmarks here

valdo404 commented 5 years ago

Hey @plokhotnyuk it is interesting. As you may know we are also managing protobuf and openrtb extensions, so we may need to adapt your examples a little bit. Do you want to provide a pr ?

plokhotnyuk commented 5 years ago

@valdo404 Please try and leave your feedback here. I can help with review, profiling and tuning.

atais commented 5 years ago

@valdo404 we have implemented full open rtb support, meaning encoding and decoding, with jsoniter.

From my experience/point of view you can't just generate the whole model based on case classes, but it depends on the approach :)

Anyway, jsoniter is a lot faster than circe.

I did not know of this project existence so let me check if we could benefit from each other's work :)

valdo404 commented 5 years ago

Thanks atais. the interesting thing here is that we provide compatibility with protobuf and ssps as well (like bidswitch). For this we created an extension system, which also compatible with protobuf extensions. For all those reasons (plus other ones) we cannot just generate derivations. serde needs to be tweaked.

atais commented 5 years ago

@valdo404 just fyi we did not realize there is a google protobuf project available :disappointed: and we simply recreated the whole OpenRTB model from the IAB specs.

So, god damn, our parsers are for sure not compatible with that model.

We are not using protobuf extensions either, so our way is completely different.

Still, I am curious how jsoniter performs against jackson - available here: https://github.com/google/openrtb/tree/master/openrtb-core/src/main/java/com/google/openrtb/json

We will have a look into google model, which could give us more flexibility and reduce our codebase, but I need some time. Tbh it is not a top priority. I could help you with the parsers as well if you start writing them since we have spent some pleasant time with jsoniter ;)

plokhotnyuk commented 5 years ago

@atais I can bet 1 PLN that jsoniter-scala will outperform protobuf parsers for Java/Scala on bid request messages with the same payload. Here is a more than 1yo benchmark with results while for the different domain, but jsoniter-scala evolved a lot since...

valdo404 commented 5 years ago

Guys it is hard to beat scalapb project (especially because protobuf is very compact and requires less memory allocs) But if by chance you can beat scalapb project let me know !

valdo404 commented 5 years ago

@atais scala openrtb is based on google openrtb project since it is relying on same .proto files. We have 100% compatibility with them.

atais commented 5 years ago

@valdo404 just quick note on circe vs jsoniter decoding performance

We have both circe and jsoniter serde and this is the benchmark:

::Benchmark decoding.circe::
cores: 4
name: Java HotSpot(TM) 64-Bit Server VM
osArch: amd64
osName: Linux
vendor: Oracle Corporation
version: 25.201-b09
Parameters(times -> 10): 5.111939
Parameters(times -> 40): 19.39121
Parameters(times -> 70): 33.482897
Parameters(times -> 100): 47.864702

::Benchmark decoding.jsoniter::
cores: 4
name: Java HotSpot(TM) 64-Bit Server VM
osArch: amd64
osName: Linux
vendor: Oracle Corporation
version: 25.201-b09
Parameters(times -> 10): 1.688709
Parameters(times -> 40): 6.283416
Parameters(times -> 70): 10.923638
Parameters(times -> 100): 15.671711

so its ~3x difference, which for us was a huge benefit.

plokhotnyuk commented 5 years ago

My figures show 3.5x - 4x speed up over circe for a 1.5K sample of the most common input depending on version of JDK/GraalVM:

image

plokhotnyuk commented 3 years ago

Currently GraalVM is preferable for parsing of OpenRTB with jsoniter-scala or borer: image