Giter Site home page Giter Site logo

Comments (3)

thoughtpolice avatar thoughtpolice commented on July 17, 2024

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.

thoughtpolice avatar thoughtpolice commented on July 17, 2024

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.

jberryman avatar jberryman commented on July 17, 2024

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)

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.