Skip to content

Comments

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

Open
ronanM wants to merge 28 commits intoKirill5k:masterfrom
ronanM:bson-derivation
Open

[WIP] Add generic derivation to org.bson.BsonValue#19
ronanM wants to merge 28 commits intoKirill5k:masterfrom
ronanM:bson-derivation

Conversation

@ronanM
Copy link
Contributor

@ronanM ronanM commented Aug 17, 2022

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"

@Kirill5k
Copy link
Owner

Wow, this is beyond my understanding of Scala 😅

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

@ronanM
Copy link
Contributor Author

ronanM commented Aug 17, 2022

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
Copy link
Contributor Author

ronanM commented Aug 20, 2022

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

@lenguyenthanh
Copy link
Contributor

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

@ronanM
Copy link
Contributor Author

ronanM commented Jun 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants