mongo4cats
mongo4cats copied to clipboard
[WIP] Add generic derivation to org.bson.BsonValue
Add Magnolia generic derivation to org.bson.BsonValue for Scala 2.12, 2.13 and 3 (with minimalist test).
The aim of this work is to encode/decode like mongo4cats-circe but directly from ADT to org.bson.BsonValue.
Tests using:
$ sbt "~+mongo4cats-bson-derivation/testQuick"
Wow, this is beyond my understanding of Scala :sweat_smile:
Sorry, I've just pushed some changes which might interfere with your PR
What I want is to use org.bson.BsonValue (used in fine by Java mongodb-driver-core) and use compile-time Codecs as we do usually in Scala without any intermediary data-structures for performance.
I have added a small PoC: https://github.com/Kirill5k/mongo4cats/blob/7a4890d82a2291d9e8da243fdd0d2ae6d4ed2bb4/bson-derivation/src/test/scala-2/mongo4cats/MongoBsonCollectionSpec.scala
I've had added some benches.
Read:
[info] Benchmark Mode Cnt Score Error Units
[info] DerivationReadBench.readViaCirce thrpt 3 134,228 ± 91,783 ops/ms
[info] DerivationReadBench.readViaDerivation thrpt 3 346,742 ± 80,683 ops/ms
Write:
[info] Benchmark Mode Cnt Score Error Units
[info] DerivationWriteBench.writeViaCirce thrpt 3 168,535 ± 10,009 ops/ms
[info] DerivationWriteBench.writeViaDerivation thrpt 3 1066,518 ± 167,060 ops/ms
The benchmark looks really great, is there anything I can help to move this forward @Kirill5k @ronanM ?
From my part, I have no more time to work on this.
This PoC is highly unsafe/low-level (reduce the allocations as much as possible) in comparison to the safety of Circe.