Skip to content

Commit

Permalink
[perf] Use shared instance of the encoder (socketio#2825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Atkinson authored and darrachequesne committed Jan 16, 2017
1 parent 2efd192 commit 6d4b58b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ var url = require('url');

module.exports = Client;

/**
* Packet encoder
*/

var encoder = new parser.Encoder();

/**
* Client constructor.
*
Expand All @@ -24,7 +30,6 @@ module.exports = Client;
function Client(server, conn){
this.server = server;
this.conn = conn;
this.encoder = new parser.Encoder();
this.decoder = new parser.Decoder();
this.id = conn.id;
this.request = conn.request;
Expand Down Expand Up @@ -153,9 +158,7 @@ Client.prototype.packet = function(packet, opts){
if ('open' == this.conn.readyState) {
debug('writing packet %j', packet);
if (!opts.preEncoded) { // not broadcasting, need to encode
this.encoder.encode(packet, function (encodedPackets) { // encode, then write results to engine
writeToEngine(encodedPackets);
});
encoder.encode(packet, writeToEngine); // encode, then write results to engine
} else { // a broadcast pre-encodes a packet
writeToEngine(packet);
}
Expand Down

0 comments on commit 6d4b58b

Please sign in to comment.