Improve array decoding performance#32
Conversation
|
For large arrays performance difference can be even bigger and also it will produce less trash for GC |
Codecov Report
@@ Coverage Diff @@
## master #32 +/- ##
==========================================
+ Coverage 96.14% 96.14% +<.01%
==========================================
Files 14 14
Lines 752 753 +1
Branches 158 158
==========================================
+ Hits 723 724 +1
Misses 12 12
Partials 17 17
Continue to review full report at Codecov.
|
|
Tested with this benchmark script: /* eslint-disable no-console */
import { encode, decode } from "../src";
// @ts-ignore
import _ from "lodash";
const data = _.cloneDeep(new Array(1000).fill([[1], [1, 2, 3], [1, 2, 3, 4, 5]]));
// warm up
const encoded = encode(data);
decode(encoded);
// run
console.time("encode");
for (let i = 0; i < 10000; i++) {
encode(data);
}
console.timeEnd("encode");
console.time("decode");
for (let i = 0; i < 10000; i++) {
decode(encoded);
}
console.timeEnd("decode");And this PR significantly improves decoding: before: after: Great! |
|
(CI failed because of SauceLabs credentials; will fix it later https://docs.travis-ci.com/user/environment-variables/ ) |
|
I wonder if you could improve the performance further on certain engines by allocating an array without holes in it: array: Array.from({ length: size }),Source: |
|
Tried it, but |
Hi @gfx I've used this msgpack library in my project and found small optimization that improves decoding speed by 3-4%.