Comments (3)
Can you explain it?
from libcbor.
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.
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)
- Make cbor_encode_half respect NaN data bits
- Improve streaming parser documentation, especially for error state handling
- Improve test coverage of cbor_bytestring_add_chunk failure scenarios
- Add [[nodiscard]] attribute
- Broken encoding of empty byte strings in 0.10.0 HOT 1
- FR: Vectorization HOT 1
- test_serialize_4b_bytestring / test_serialize_8b_bytestring tests fail on 32-bit systems (size_t overflow) HOT 2
- Better documentation for memory management
- Documentation references RFC 7049, which has been replaced by RFC 8949 (STD94).
- Testing for musl HOT 3
- Signaling NaN encoding broken on Windows
- Improvements for examples HOT 1
- Need to use cbor as library HOT 1
- Out of bound pointer in cbor_build_bytestring HOT 1
- Broken CMake configuration HOT 2
- cbor_load returns CBOR_ERR_MALFORMATED parsing the assigned tags for cose-encrypt0 (16), cose-mac0 (17), and cose-sign1 (18) HOT 1
- Visual Studio enabling of SDL Checks causes failure
- Decode a CBOR Map type payload HOT 2
- Make libcbor compatible with PlatformIO HOT 4
- It doesn't seem possible to disable LTO HOT 1
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 libcbor.