Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve array decoding performance #32

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

Merged
gfx merged 1 commit into msgpack:master from sergeyzenchenko:master
May 28, 2019
Merged

Conversation

Copy link
Collaborator

@sergeyzenchenko sergeyzenchenko commented May 27, 2019

Hi @gfx I've used this msgpack library in my project and found small optimization that improves decoding speed by 3-4%.

Copy link
Collaborator Author

For large arrays performance difference can be even bigger and also it will produce less trash for GC

Copy link

Codecov Report

Merging #32 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@ 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
Impacted Files Coverage Δ
src/Decoder.ts 99.27% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c022de5...3d50366. Read the comment docs.

Copy link
Member

gfx commented May 28, 2019

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:

$ npx ts-node benchmark/sandbox.ts
encode: 2753.986ms
decode: 1855.263ms

after:

$ npx ts-node benchmark/sandbox.ts
encode: 2393.308ms
decode: 3804.347ms

Great!

Copy link
Member

gfx commented May 28, 2019

(CI failed because of SauceLabs credentials; will fix it later https://docs.travis-ci.com/user/environment-variables/ )

@gfx gfx merged commit 2589c87 into msgpack:master May 28, 2019
Copy link

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:
https://v8.dev/blog/elements-kinds
https://2ality.com/2018/12/creating-arrays.html

Copy link
Member

gfx commented Jul 3, 2019
edited
Loading

Tried it, but Array.from({ length: size }) makes decoding 10x slower than new Array(size) :-(

shitpoet reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /