Giter Site home page Giter Site logo

Comments (18)

dakrone avatar dakrone commented on August 19, 2024

Is there an obvious way to implement this with the existing cheshire design?

Not that I can immediately think of, I will have to experiment to see if there already is.

Is this a feature that would be welcome for cheshire if I implemented it?

Yes, definitely would be nice as long as it does not negatively affect performance.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

This has been a big pain point for me as well.

One option I just thought of is to have another option that can be passed of a :fallback-encoder -- an encoder function that gets used whenever the JsonGenerationException would otherwise be thrown. Presumably that wouldn't be a big perf problem (at least for people not using it) since it's only a code change in an otherwise-exceptional codepath.

For my use cases I think the fallback encoder would pretty much always just use str, so we could also consider adding a feature that just does that, or at least an easier way to opt into that than an actual encoder fn.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

Though now that I look through the implementation I remember that options are passed around as first-class args, and so having an extra option means expanding the signatures everywhere :/

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

If the signature thing is a big perf deal, maybe an internal dynamic var that gets set once at the top level would be an alternative.

from cheshire.

dakrone avatar dakrone commented on August 19, 2024

I remember that options are passed around as first-class args, and so having an extra option means expanding the signatures everywhere :/

I'd need to check the performance hit for it, but if it's not too much, a breaking change (Cheshire 6.x) to switch to a map of options would be better for future development.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

I'll see if I can quickly make a branch with the options-map change.

from cheshire.

dakrone avatar dakrone commented on August 19, 2024

Okay, remember not to use destructuring as that (unfortunately) causes a big performance hit.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

do you just mean destructuring when you don't actually need all the keys? When I macroexpand a {:keys [foo bar]} destructuring the only extra thing I see is a (seq? m) check, is that the bad part?

from cheshire.

dakrone avatar dakrone commented on August 19, 2024

I haven't dug into why it's slower yet, only that it was slower in benchmarks (heck, maybe Clojure has caught up and it's better in recent versions?), so it would be good to test and see.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

okay; it ought to be identical to the macroexpanded code, but regardless I will leave it out so we don't have to wonder

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

Okay I have some code here that seems to work except for some bug in the generate-seq code that I don't have time to chase down at the moment. Hopefully the non-seq code is correct and adequate for perf tests.

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

(bug indicated by the one test failure)

from cheshire.

dakrone avatar dakrone commented on August 19, 2024

Okay I have some code here that seems to work

Great, thanks! No guarantees for when I will be able to look as my wife just had a baby and I am short on sleep/free-time, but I will try to take a look whenever I can! :)

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

babies babies babies babies babies babies babies babies babies babies babies babies!

from cheshire.

dakrone avatar dakrone commented on August 19, 2024

@gfredericks I finally had a second to check out your branch. Performance-wise it looks good to me, would you be able to open a PR for moving to it?

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

Will do

from cheshire.

gfredericks avatar gfredericks commented on August 19, 2024

In terms of an API for extending via opts, the code used in greglook/puget#23 will probably be relevant.

from cheshire.

ikitommi avatar ikitommi commented on August 19, 2024

Any news on this? Looking also forward to this, config similar like the edn / transit readers?

from cheshire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.