Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate performance impact of dynamic callbacks in cbor_stream_decode #26

Open
PJK opened this issue Nov 8, 2016 · 3 comments
Open

Comments

@PJK
Copy link
Owner

PJK commented Nov 8, 2016

Maybe it's worth it to 'specialize' for cbor_load?

@PJK PJK added the help wanted label Nov 8, 2016
@kyursen
Copy link
Contributor

kyursen commented Nov 9, 2016

Can you explain it?

@PJK
Copy link
Owner Author

PJK commented Nov 9, 2016

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.

@kyursen
Copy link
Contributor

kyursen commented Nov 10, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants