-
-
Couldn't load subscription status.
- Fork 41
feature/issue-175-auto #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Re-enable many tests
…into feature/issue-175-auto
|
Fixed merge conflicts |
|
Thank you for the update, I just got back from vacation will have a look to make a new Thoth.Json release this week and take this chance to look at the Auto API support once again. |
|
Hello @njlr, I am finally starting to have a look at this PR seriously. Looking at the code it seems like there are a lot of changes compared to the originals versions, do you remember what motivated these changes? For example, you seems to use this pattern a lot: #if FABLE_COMPILER
let fail (innerType: Type) (x: string) : obj =
Decode.fail x |> box
#else
let private failGenericMethodDefinition =
getGenericMethodDefinition "Fail"
let fail (innerType: Type) (x: string) : obj =
failGenericMethodDefinition
.MakeGenericMethod([| innerType |])
.Invoke(null, [| x |])
#endifinstead of probably the type private DecoderCrate<'T>(dec: Decoder<'T>) =
inherit BoxedDecoder()
override __.Decode(path, token) =
match dec path token with
| Ok v -> Ok(box v)
| Error er -> Error er
member __.UnboxedDecoder = dec
let boxDecoder (d: Decoder<'T>): BoxedDecoder =
DecoderCrate(d) :> BoxedDecoder
let unboxDecoder<'T> (d: BoxedDecoder): Decoder<'T> =
(d :?> DecoderCrate<'T>).UnboxedDecoderIs it because it improves something over the crate? |
Sorry, it has been a while! IIRC, the thinking is to move all reflection and dynamic casts to the encoder/decoder generation step and out of the encode/decode stage. In theory this offers better performance for the most common use-case: generate an encoder/decoder once and then call it many times. The Auto module uses reflection to invoke the core API in an automatic way, but does not contain any special encoder/decoder types. |
|
Ok thank you for the answer. At least now, Thoth.Json has benchmark setup so it should be possible to make a quick comparaison between both approach an see which one works the best at least for .NET. |
|
If you ever get a chance, this would be pretty nice to have. Using some simple workarounds to get extra coders working on both Fable and .NET 9 right now. |
Sorry, I had forgotten about this PR but agree it would still be useful! @MangelMaxime What are the next steps needed? |
|
Originally, I wanted to make a benchmark comparison between your version of the Auto decoders and the old ways of doing them. But I don't think it matters too much to me, I am not focused on performance for Thoth.Json.Core. I mean the new API is slower than the previous one because of its modularity but that's also its strength. I always wanted to get this PR merged, but always kept postponing it ... I think we all have this kind of PR siting around that we "fear" and I need to face it 🤣 Let's make a plan for releasing Auto API support with Thoth.Json.Core API.
|
|
Thanks for doing this! I agree, I'm also happy to do some caching if that's what I need to do to enjoy Thoth's ergonomics. |
With .NET 10 optimizations, it may actaully be faster. This would need to be measured, however.
I know the feeling!
I was hoping that the Auto API could live in a different package so that compilation targets with limited reflection support can use the Core API.
I don't mind who the author is, whatever is easiest to make progress 🙂
At a glance, I think all of these are fixable under the new approach. |
I probably wrongly explained my self, the Auto API will be in it own packages yes. When I talk about Thoth.Json.Core API this is to make a distinction between the legacy and the new APIs. |
I wonder - could we merge this as-is and release Auto API under an experimental pre-1.0 version so people can use at their own risk? Meanwhile we can start working through the tickets you listed above and shake out any issues? |
…into feature/issue-175-auto
Tag: auto
Switches back to lossy option to match tests Tag: auto
Tag: system.text.json
|
This works locally: # nix develop
./build/sh testEdit: |
This PR introduces an Auto module that is agnostic to the JSON backend used. It does this by composing Encoders / Decoders from
Thoth.Json.Coreusing reflection. There is some Fable specific stuff to pave over the limitation of reflection for some targets.The majority of the old tests are re-enabled and unchanged.
LMK what you think!