Giter Site home page Giter Site logo

Comments (13)

dakrone avatar dakrone commented on July 19, 2024

Yes, macro-unrolling dispatch is about ~26% faster than protocol dispatch.

edit: in cheshire's case, not the general case.

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

If you run the :benchmark tests, compare the Custom, bypass core with custom fields and the Core Benchmarks times to see the difference.

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

Although, now that I think about it, I might be able to make fall-through for cheshire.generate go directly to protocol dispatch, so regular dispatch would still be fast, and custom would only be used when needed.

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

Having great luck with this. I may be able to deprecate the custom namespace after all. I'll keep you posted as it progresses.

from cheshire.

weavejester avatar weavejester commented on July 19, 2024

Thank you for looking into this.

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

I've just released 5.0.0, which deprecates the cheshire.custom namespace in favor of falling back to protocol dispatch in the event of custom types.

All the add-encoder and remove-encoder stuff has been moved to cheshire.generate.

This was a good idea, it allows us to retain the performance for regular encoding, and seamless custom encoding in the same namespace (now only cheshire.core is needed).

Let me know if you have any problems with it.

from cheshire.

weavejester avatar weavejester commented on July 19, 2024

This was a good idea, it allows us to retain the performance for regular encoding, and seamless custom encoding in the same namespace (now only cheshire.core is needed).

If I'm completely honest, I'm not sure how much of this was luck on my part that this panned out, but I'm glad that you were able to give Cheshire the best of both worlds!

from cheshire.

lynaghk avatar lynaghk commented on July 19, 2024

The toplevel condp used by generate prevents custom serialization of things that implement Clojure protocols.
E.g., all Clojure records are instances of java.util.Map, so even if I extend my record with the JSONable protocol they will still be printed out using generate-map instead of my custom implementation.

Why is there a condp to do manual dispatch instead of relying on Clojure's protocol dispatch?

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

@lynaghk As I mentioned before, macro unrolling with a condp is about ~26% faster than Clojure's protocol dispatch.

I'll definitely take a look at custom protocol generation and get that fixed, thanks for letting me know about it.

from cheshire.

lynaghk avatar lynaghk commented on July 19, 2024

@dakrone Yeah, I don't know anything about timing but maybe you can just do a (satisifies? JSONable x) first, then delegate to the condp tree. Thanks for taking the time to check this out.

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

@lynaghk I've committed a fix for this, can you give it a try with Cheshire's master branch and let me know if that'll work for you? If it does, I'll do a released with this fix.

from cheshire.

lynaghk avatar lynaghk commented on July 19, 2024

Confirmed, this works great. Thanks @dakrone.

(ns foo
  (:require cheshire.core
            [cheshire.generate :refer [JSONable to-json]]))

(defrecord X [a]
  JSONable
  (to-json [this jg]
    (.writeString jg "123")))

(let [x (X. 1)]
  (cheshire.core/generate-string x)) ;;=> "\"123\"" 

from cheshire.

dakrone avatar dakrone commented on July 19, 2024

@lynaghk I've released 5.0.1 with this fix, thanks for bringing it to my attention!

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.