mongo4cats icon indicating copy to clipboard operation
mongo4cats copied to clipboard

[WIP] Add generic derivation to org.bson.BsonValue

Open ronanM opened this issue 3 years ago • 5 comments

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"

ronanM avatar Aug 17 '22 17:08 ronanM

Wow, this is beyond my understanding of Scala :sweat_smile:

Sorry, I've just pushed some changes which might interfere with your PR

Kirill5k avatar Aug 17 '22 18:08 Kirill5k

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

ronanM avatar Aug 17 '22 21:08 ronanM

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

ronanM avatar Aug 20 '22 19:08 ronanM

The benchmark looks really great, is there anything I can help to move this forward @Kirill5k @ronanM ?

lenguyenthanh avatar Jun 23 '24 03:06 lenguyenthanh

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.

ronanM avatar Jun 23 '24 07:06 ronanM