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

CBOR codec usage can easily be optimized by not recreating options and modes each time #188

Open
x448 opened this issue Jun 25, 2023 · 0 comments
Assignees
Labels
performance Performance improvement, benchmarks

Comments

@x448
Copy link

x448 commented Jun 25, 2023

The CBOR codec is optimized for encoding and decoding modes to be created at startup just once and then reused concurrently.

Recreating options & modes on each call to encode like this creates overhead:

em, err := cbor.EncOptions{Sort: cbor.SortCanonical}.EncMode()

Quick Start has a section about using modes:
https://github.com/fxamacker/cbor#quick-start

Here's a more extensive example with security considerations:
https://github.com/x448/safer-cbor/blob/master/cbor.go.txt

For determinism, this returns presets for Core Deterministic Encoding Requirements as defined in IETF STD 94 (RFC 8949):

func CoreDetEncOptions() EncOptions
@lquerel lquerel self-assigned this Jul 1, 2023
@lquerel lquerel added the performance Performance improvement, benchmarks label Jul 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance improvement, benchmarks
Projects
None yet
Development

No branches or pull requests

2 participants