Skip to content
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

Improved performance of Pipeline.exec #991

Merged
merged 2 commits into from Nov 22, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/pipeline.ts
Expand Up @@ -303,6 +303,7 @@ Pipeline.prototype.exec = function(callback: CallbackFunction) {

function execPipeline() {
let data: Buffer | string = "";
let buffers: Buffer[];
let writePending: number = (_this.replyPending = _this._queue.length);

let node;
Expand All @@ -319,16 +320,25 @@ Pipeline.prototype.exec = function(callback: CallbackFunction) {
bufferMode = true;
}
if (bufferMode) {
data = Buffer.concat([
typeof data === "string" ? Buffer.from(data, "utf8") : data,
if (!buffers) {
buffers = [];
}
if (typeof data === "string") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data is ignored if its already a buffer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data cannot be a Buffer. I cleaned up the code a bit to make this clear.
Your comment made me aware that buffers is actually never re-set, so I did that, too.

buffers.push(Buffer.from(data, "utf8"));
data = undefined;
}
buffers.push(
typeof writable === "string"
? Buffer.from(writable, "utf8")
: writable
]);
);
} else {
data += writable;
}
if (!--writePending) {
if (buffers) {
data = Buffer.concat(buffers);
}
if (_this.isCluster) {
node.redis.stream.write(data);
} else {
Expand Down