Comments (3)
What sort of performance are you seeing in general? Can you give an expectation of the benchmark and the data size, application characteristics, etc so we could try to replicate any possible problems? What leads you to believe the Generic
instances are at play here? Does this exact example get faster if you write them out manually? It's hard to directly evaluate without answering all these.
Briefly: at a glance, it's not really surprising that cereal
does OK in micro benchmarks vs cbor
. In fact, our own benchmarks should basically say as much - they do very well when serializing very tiny things in very simple examples. There's not much code to 'blind' the optimizer with a small set of types and values, so it will normally do OK inlining and unboxing away the intermediate states. Indeed, with a closed world single-module where all instances live there, and all data is static like your example, GHC will probably do very well (and why wouldn't it? it can easily constant propagate all those values through large parts of the program.) But the problem is both cereal
and binary
fundamentally is that they generate lots of code for creating an instance, and this really can't be avoided, and incurs fundamental overheads (fragile global optimization to optimize away/unbox intermediates, the costs of allocating continuations, etc. If you change a type and the optimizer suddenly starts failing because something became 'too big' or somesuch, you'll be annoyed and sad).
If you have like, a really large value, I'd expect cbor to be a lot better - as an example, try the vs-other-libs
benchmark, the Macro.hs
link you included is part of it. It should show that for large things, cbor
handily beats out binary
and serialise
in both paths by quite a lot.
from cborg.
Just a thought: if you replace Macro.hs
in vs-other-libs
with a version that has Generic
-derived Serialise
instances, perhaps that would lend evidence to Generic
being the culprit if there was a large discrepancy?
from cborg.
Just a thought: if you replace Macro.hs in vs-other-libs with a version that has Generic-derived Serialise instances
Yeah that would be a good idea for comparison. This ticket was more like "here's my realistic example where I found cbor to be not significantly faster than cereal. I happen to (need to) be using Generic-derived instances so I mentioned it in the title.
I'm just going to close this. I'll try to contribute some benchmarks as PRs if I get to pursue this. Thanks for the reply.
from cborg.
Related Issues (20)
- Support GHC 9.4 HOT 1
- cborg-0.2.6+ fails to build for 32bit: Couldn't match expected type βInt64#β with actual type βInt#β etc HOT 3
- Alternative tags have now been standardised
- Build error on ghc 9.2.2 HOT 2
- `serialise` `versus` benchmark fails to parse internal cabal libraries
- Allow vector-0.13 (in serialise) HOT 2
- Add instances for wide-word
- cborg-0.2.8.0 fails to build with 32bit ghc9 HOT 2
- Support base-4.18, strict-0.5, these-1.2, criterion-1.6 (i.e. GHC-9.6) HOT 2
- ghc-9.4 build error on M1 HOT 6
- Test `decodeValue` against `Reference.termToJson`.
- hPutSerialise should use hPutBuilder? HOT 1
- Encoding allocates too many blocks in old generation HOT 3
- Remove dependency on `aeson-pretty`
- fromFlatTerm impl of PeekTokenType is insufficently precise
- Support ghc-9.8.1 HOT 4
- serialise: Usage without requiring `Serialise` instances HOT 3
- serialise: allow tar-0.6
- serialise: allow zlib-0.7
- Versions on master have fallen behind Hackage
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 cborg.