Giter Club home page Giter Club logo

Comments (3)

kyursen avatar kyursen commented on May 29, 2024

Can you explain it?

from libcbor.

PJK avatar PJK commented on May 29, 2024

Gladly :) At the moment, the cbor_load function uses the streaming interface (cbor_stream_decode) that takes a bundle of callbacks as a parameters (struct cbor_callbacks).

These callbacks define what to when the streaming decoder encounters e.g. a number or an array. The callbacks cbor_load provides to the function are always the same, and they simply build an internal representation in the memory.

This is a nicely layered architecture that allows users to plug in different callbacks. For instance, when you just want extract particular map keys, there's no need to build a modifiable representation in the memory -- just have the callback filter them out.

The downside, of course, is that these callback bundles are passed in at the runtime, thus the compiler cannot assume which particular function will be called in which branch of cbor_stream_decode. This is the case even when cbor_load invokes it, despite it always passing the same callbacks.

Since cbor_load is a central function of the library, it could make sense to get rid of this unnecessary dereference and possibly also allow further optimizations by having a 'specialized' version of cbor_stream_decode where the callbacks are used statically in the source.

The goal is to try implementing this (should be just a couple of minutes), and, more importantly, evaluate the impact of these changes to see whether it is worthwhile to maintain such specialization separately.

If the results are good, a similar interface could also be exposed to users via a (probably exceedingly ugly) macro to plug in their own callbacks at the compile time.

Keep in mind that the dynamic passing is crucial for FFI clients and thus has to remain supported.

I have a benchmarking setup that I can partially share if anyone is wiling to look into this.

from libcbor.

kyursen avatar kyursen commented on May 29, 2024

Thank you for details.

I've ran some simple tests and I didn't see any significant difference between current decoder (with dynamic callbacks) and specialized one (based on direct calls to cbor_builder_x_callback).

Could you share your benchmarks please?

from libcbor.

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.