redis-parser
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,16 @@ | ||
## v.2.3.0 - 25 Nov, 2016 | ||
Features | ||
- Parsing time for big arrays (e.g. 4mb+) is now linear and works well for arbitrary array sizes | ||
This case is a magnitude faster than before | ||
OLD STR: * big array x 1.09 ops/sec ±2.15% (7 runs sampled) | ||
OLD BUF: * big array x 1.23 ops/sec ±2.67% (8 runs sampled) | ||
NEW STR: * big array x 273 ops/sec ±2.09% (85 runs sampled) | ||
NEW BUF: * big array x 259 ops/sec ±1.32% (85 runs sampled) | ||
(~10mb array with 1000 entries) | ||
## v.2.2.0 - 18 Nov, 2016 | ||
@@ -2,0 +17,0 @@ |
@@ -208,7 +208,30 @@ 'use strict' | ||
} | ||
var responses = new Array(length) | ||
return parseArrayElements(parser, responses, 0) | ||
} | ||
var responses = new Array(length) | ||
var bufferLength = parser.buffer.length - 3 | ||
for (var i = 0; i < length; i++) { | ||
/** | ||
* Parse chunked redis array response | ||
* @param parser | ||
* @returns {*} | ||
*/ | ||
function parseArrayChunks (parser) { | ||
return parseArrayElements(parser, parser.arrayCache, parser.arrayPos) | ||
} | ||
/** | ||
* Parse redis array response elements | ||
* @param parser | ||
* @param responses | ||
* @param i | ||
* @returns {*} | ||
*/ | ||
function parseArrayElements (parser, responses, i) { | ||
var bufferLength = parser.buffer.length | ||
while (i < responses.length) { | ||
var offset = parser.offset | ||
if (parser.offset >= bufferLength) { | ||
parser.arrayCache = responses | ||
parser.arrayPos = i | ||
parser.offset = offset | ||
return | ||
@@ -218,5 +241,9 @@ } | ||
if (response === undefined) { | ||
parser.arrayCache = responses | ||
parser.arrayPos = i | ||
parser.offset = offset | ||
return | ||
} | ||
responses[i] = response | ||
i++ | ||
} | ||
@@ -302,2 +329,4 @@ | ||
this.bufferCache = [] | ||
this.arrayCache = null | ||
this.arrayPos = 0 | ||
} | ||
@@ -326,3 +355,2 @@ | ||
chunks-- | ||
offset = list[list.length - 2].length + 1 | ||
} | ||
@@ -406,2 +434,3 @@ var res = decoder.write(list[0].slice(parser.bigOffset)) | ||
JavascriptRedisParser.prototype.execute = function execute (buffer) { | ||
var arr | ||
if (this.buffer === null) { | ||
@@ -418,14 +447,30 @@ this.buffer = buffer | ||
this.offset = 0 | ||
if (this.arrayCache) { | ||
arr = parseArrayChunks(this) | ||
if (!arr) { | ||
return | ||
} | ||
this.returnReply(arr) | ||
this.arrayCache = null | ||
} | ||
} else if (this.totalChunkSize + buffer.length >= this.bigStrSize) { | ||
this.bufferCache.push(buffer) | ||
// The returned type might be Array * (42) and in that case we can't improve the parsing currently | ||
if (this.optionReturnBuffers === false && this.buffer[this.offset] === 36) { | ||
if (this.optionReturnBuffers === false && !this.arrayCache) { | ||
this.returnReply(concatBulkString(this)) | ||
this.buffer = buffer | ||
} else { // This applies for arrays too | ||
} else { | ||
this.buffer = concatBuffer(this, this.totalChunkSize + buffer.length) | ||
this.offset = 0 | ||
if (this.arrayCache) { | ||
arr = parseArrayChunks(this) | ||
if (!arr) { | ||
this.bigStrSize = 0 | ||
this.bufferCache = [] | ||
return | ||
} | ||
this.returnReply(arr) | ||
this.arrayCache = null | ||
} | ||
} | ||
this.bigStrSize = 0 | ||
this.totalChunkSize = 0 | ||
this.bufferCache = [] | ||
@@ -443,3 +488,5 @@ } else { | ||
if (response === undefined) { | ||
this.offset = offset | ||
if (!this.arrayCache) { | ||
this.offset = offset | ||
} | ||
return | ||
@@ -446,0 +493,0 @@ } |
{ | ||
"name": "redis-parser", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"description": "Javascript Redis protocol (RESP) parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,5 +14,3 @@ [![Build Status](https://travis-ci.org/NodeRedis/node-redis-parser.png?branch=master)](https://travis-ci.org/NodeRedis/node-redis-parser) | ||
``` | ||
npm install redis-parser | ||
``` | ||
npm install redis-parser | ||
@@ -98,10 +96,56 @@ ## Usage | ||
``` | ||
npm install | ||
npm test | ||
npm run benchmark | ||
``` | ||
npm install | ||
npm test | ||
npm run benchmark | ||
Currently the benchmark compares the performance against the hiredis parser: | ||
HIREDIS: $ multiple chunks in a bulk string x 867,643 ops/sec ±1.39% (82 runs sampled) | ||
HIREDIS BUF: $ multiple chunks in a bulk string x 591,398 ops/sec ±1.48% (83 runs sampled) | ||
JS PARSER: $ multiple chunks in a bulk string x 942,834 ops/sec ±0.87% (90 runs sampled) | ||
JS PARSER BUF: $ multiple chunks in a bulk string x 1,081,096 ops/sec ±1.81% (85 runs sampled) | ||
HIREDIS: + multiple chunks in a string x 1,785,222 ops/sec ±0.59% (92 runs sampled) | ||
HIREDIS BUF: + multiple chunks in a string x 902,391 ops/sec ±1.62% (88 runs sampled) | ||
JS PARSER: + multiple chunks in a string x 1,936,709 ops/sec ±1.07% (90 runs sampled) | ||
JS PARSER BUF: + multiple chunks in a string x 1,954,798 ops/sec ±0.84% (91 runs sampled) | ||
HIREDIS: $ 4mb bulk string x 344 ops/sec ±1.40% (85 runs sampled) | ||
HIREDIS BUF: $ 4mb bulk string x 555 ops/sec ±1.85% (80 runs sampled) | ||
JS PARSER: $ 4mb bulk string x 834 ops/sec ±1.23% (81 runs sampled) | ||
JS PARSER BUF: $ 4mb bulk string x 620 ops/sec ±2.40% (59 runs sampled) | ||
HIREDIS: + simple string x 2,344,042 ops/sec ±1.45% (91 runs sampled) | ||
HIREDIS BUF: + simple string x 993,081 ops/sec ±1.87% (83 runs sampled) | ||
JS PARSER: + simple string x 4,431,517 ops/sec ±1.86% (88 runs sampled) | ||
JS PARSER BUF: + simple string x 5,259,552 ops/sec ±0.61% (96 runs sampled) | ||
HIREDIS: : integer x 2,376,642 ops/sec ±0.30% (92 runs sampled) | ||
JS PARSER: : integer x 17,765,077 ops/sec ±0.53% (93 runs sampled) | ||
JS PARSER STR: : integer x 13,110,365 ops/sec ±0.67% (91 runs sampled) | ||
HIREDIS: : big integer x 2,010,124 ops/sec ±0.87% (86 runs sampled) | ||
JS PARSER: : big integer x 10,277,063 ops/sec ±0.69% (91 runs sampled) | ||
JS PARSER STR: : big integer x 4,492,626 ops/sec ±0.67% (94 runs sampled) | ||
HIREDIS: * array x 43,763 ops/sec ±0.84% (94 runs sampled) | ||
HIREDIS BUF: * array x 13,893 ops/sec ±1.05% (85 runs sampled) | ||
JS PARSER: * array x 50,825 ops/sec ±1.92% (80 runs sampled) | ||
JS PARSER BUF: * array x 72,546 ops/sec ±0.80% (94 runs sampled) | ||
HIREDIS: * big array x 265 ops/sec ±1.46% (86 runs sampled) | ||
HIREDIS BUF: * big array x 226 ops/sec ±3.21% (75 runs sampled) | ||
JS PARSER: * big array x 201 ops/sec ±0.95% (83 runs sampled) | ||
JS PARSER BUF: * big array x 244 ops/sec ±2.65% (81 runs sampled) | ||
HIREDIS: - error x 81,563 ops/sec ±0.51% (93 runs sampled) | ||
JS PARSER: - error x 155,225 ops/sec ±0.57% (95 runs sampled) | ||
Platform info: | ||
Ubuntu 16.10 | ||
Node.js 7.1.0 | ||
Intel(R) Core(TM) i7-5600U CPU | ||
## License | ||
[MIT](./LICENSE) |
26412
12
534
150