Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

Encoding performance #23

Closed
parkan opened this issue Oct 14, 2016 · 10 comments
Closed

Encoding performance #23

parkan opened this issue Oct 14, 2016 · 10 comments
Assignees

Comments

@parkan
Copy link

parkan commented Oct 14, 2016

We're running some large-scale ingestions involving CBOR encoding and we're seeing this kind of performance per 1k objects:

pure js: 1.3s
tinycbor (C/C++): 0.06s

In this case the pure js impl is node-cbor because #22 blocks us from using js-ipld directly, but I would expect similar performance here. This is a huge difference and can potentially make or break the use case for larger datasets. We're exploring a couple of different paths here:

  • optional gyp/ffi dependency when running in node
  • webasm

Would love to work w/upstream here to deliver something that works for everyone. wasm certainly seems like a future-looking option that would work isomorphically (in a couple of months, at least 😄 ) so I am interested in exploring this path.

Corresponding issue in mediachain/aleph#27 /cc @yusefnapora

@daviddias
Copy link
Member

Hey @parkan have you looked into this again? Would love to see some benchmarks of tinycbor compiled with asm.js.

@parkan
Copy link
Author

parkan commented Oct 26, 2016

@diasdavid will hopefully have something next week!

@dignifiedquire
Copy link
Member

@parkan I have started looking into optimizing cbor encoding and decoding. Could you share your benchmark that you ran? I would like to see how close I can get in JavaScript.

@dignifiedquire
Copy link
Member

Current results, node-cbor is the default what we currently use and fast-cbor are my optimizations. Every run consists of encoding 83 small objects to cbor with most of the possible values being used.

Browser (Chrome)
encode vectors - node-cbor - 83 x 232 ops/sec ±5.34% (46 runs sampled)
encode vectors - fast-cbor - 83 x 4,248 ops/sec ±1.39% (53 runs sampled)

Node.js 7
encode vectors - node-cbor - 83 x 301 ops/sec ±5.38% (60 runs sampled)
encode vectors - fast-cbor - 83 x 3,584 ops/sec ±2.36% (74 runs sampled)

@dignifiedquire
Copy link
Member

dignifiedquire commented Nov 13, 2016

Getting faster,

Browser (Chrome)
encode vectors - fast-cbor - 83 x 5,576 ops/sec ±5.83% (33 runs sampled)

Node.js 7
encode vectors - fast-cbor - 83 x 4,061 ops/sec ±2.06% (79 runs sampled)

work is happening here: https://github.com/dignifiedquire/node-cbor/tree/perf

@dignifiedquire
Copy link
Member

Some new numbers are in

Browser (Chrome)
encode vectors - node-cbor - 83 x 198 ops/sec ±10.09% (31 runs sampled)
encode vectors - fast-cbor - 83 x 5,744 ops/sec ±1.29% (36 runs sampled)
encode vectors - JSON.stringify - 83 x 18,944 ops/sec ±7.59% (30 runs sampled)

Node.js 7
encode vectors - node-cbor - 83 x 294 ops/sec ±4.95% (58 runs sampled)
encode vectors - fast-cbor - 83 x 10,884 ops/sec ±3.30% (76 runs sampled)
encode vectors - JSON.stringify - 83 x 18,166 ops/sec ±8.90% (66 runs sampled)

so things are starting to look pretty good :)

@parkan
Copy link
Author

parkan commented Nov 14, 2016

Hi @dignifiedquire, very happy to see those numbers! Don't have the benchmark around but the difference was something like ~700 ops/s node-cbor vs ~16000 ops/s with tinycbor (under node 6.x) so this is certainly in the ballpark.

Glanced over your branch, I see a bunch of savings through precalculating buffer size and allocating once -- nice. Curious, what tooling do you use for profling/benches/etc?

@dignifiedquire
Copy link
Member

@dignifiedquire
Copy link
Member

@parkan will do a write up of techniques and things I used when it's ready to ship :)

@parkan
Copy link
Author

parkan commented Nov 17, 2016

beautiful! will benchmark this w/our datasets after deps are updated

@daviddias daviddias added the status/ready Ready to be worked label Dec 5, 2016
dignifiedquire added a commit that referenced this issue Dec 11, 2016
This makes cbor encoding and decoding a lot faster.

Fixes #23
@dignifiedquire dignifiedquire added status/in-progress In progress and removed status/ready Ready to be worked labels Dec 11, 2016
daviddias pushed a commit that referenced this issue Dec 11, 2016
This makes cbor encoding and decoding a lot faster.

Fixes #23
@daviddias daviddias removed status/in-progress In progress labels Dec 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants