Comments (13)
Yes, macro-unrolling dispatch is about ~26% faster than protocol dispatch.
edit: in cheshire's case, not the general case.
from cheshire.
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.
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.
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.
Thank you for looking into this.
from cheshire.
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.
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.
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.
@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.
@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.
@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.
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.
@lynaghk I've released 5.0.1 with this fix, thanks for bringing it to my attention!
from cheshire.
Related Issues (20)
- Cheshire library not working for longer sequences HOT 1
- Always update to latest version of Jackson, when available
- Any way to not escape the quotes HOT 2
- Suggestion: prove equivalence with clojure.data.json HOT 6
- Add support for capturing source position/locations when parsing HOT 2
- Allow key-fn like hook for value HOT 2
- Converting nested fields from java objects to clojure types doesnot work
- Custom conversion when parsing?
- `parsed-smile-seq` actually parses JSON
- Run tests against JSONTestSuite
- Resulting Array from parse not processed lazily HOT 1
- :key-fn no longer works in generate-string? HOT 1
- Using the Ubuntu Cheshire package with Clojure HOT 1
- lein unable to find cheshire on classpath HOT 1
- Security vulnerability in Jackson dependency HOT 4
- Can't convert object of type org.postgresql.util.PGobject HOT 1
- support jackson's fast number parsing/writing features HOT 1
- Update test.generative HOT 2
- Possible to support parsing copy-paste JSON? HOT 1
- Test failures with Java 21
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cheshire.