Skip to content

Improve toString() serialization performance #18

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
merged 2 commits into from
Jan 13, 2014
Merged

Improve toString() serialization performance #18

merged 2 commits into from
Jan 13, 2014

Conversation

ericf
Copy link
Collaborator

@ericf ericf commented Dec 17, 2013

Switch from array.join() to standard string concatenation to dramatically improve performance of serialization.

I ran some tests locally using process.hrtime() and using basic string concatenation is a huge improvement over using intermediate arrays.

Benchmarks

I added some benchmarks to this package to get a rough idea how it performs with a small, medium, and huge data sets.

Before

simpleObj:
JSON.stringify( simpleObj ) x 1,339,743 ops/sec ±1.02% (96 runs sampled)
serialize( simpleObj ) x 555,898 ops/sec ±1.57% (90 runs sampled)
simpleExposed.toString() x 200,108 ops/sec ±2.38% (89 runs sampled)


YUI_config:
JSON.stringify( YUI_config ) x 37,865 ops/sec ±4.20% (77 runs sampled)
serialize( YUI_config ) x 13,052 ops/sec ±2.95% (93 runs sampled)
appExposed.toString() x 8,540 ops/sec ±3.80% (89 runs sampled)


App.Cache:
JSON.stringify( App.Cache ) x 523 ops/sec ±1.69% (94 runs sampled)
serialize( App.Cache ) x 143 ops/sec ±10.35% (68 runs sampled)
resExposed.toString() x 150 ops/sec ±10.80% (75 runs sampled)

After

simpleObj:
JSON.stringify( simpleObj ) x 1,346,714 ops/sec ±0.68% (100 runs sampled)
serialize( simpleObj ) x 631,145 ops/sec ±1.22% (91 runs sampled)
simpleExposed.toString() x 361,795 ops/sec ±1.68% (96 runs sampled)


YUI_config:
JSON.stringify( YUI_config ) x 48,044 ops/sec ±0.93% (96 runs sampled)
serialize( YUI_config ) x 13,058 ops/sec ±2.20% (93 runs sampled)
appExposed.toString() x 9,140 ops/sec ±2.83% (94 runs sampled)


App.Cache:
JSON.stringify( App.Cache ) x 510 ops/sec ±1.48% (92 runs sampled)
serialize( App.Cache ) x 181 ops/sec ±1.34% (87 runs sampled)
resExposed.toString() x 189 ops/sec ±0.56% (90 runs sampled)

Switch from `array.join()` to standard string concatenation to
dramatically improve performance of serialization.
@caridy
Copy link
Contributor

caridy commented Dec 17, 2013

LGTM

I will recommend to remove all the white spaces between in those sentences to get a almost minified string :), the reason why I recommend that is because at the end of the day, the whole blob is not readable anyways.

@ericf
Copy link
Collaborator Author

ericf commented Jan 11, 2014

Added benchmark before/after results.

@ericf ericf merged commit 199368f into master Jan 13, 2014
@ericf ericf deleted the string-concat branch January 21, 2014 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants