-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add the hasBinary flag #2838
Add the hasBinary flag #2838
Conversation
Hi Andrew, Thanks for the pull request! From what I understand (and what that comment suggests), the It does not seem to be used anymore, but it's a good use-case here, what do you think? How about something like: type: !this.flags.json && hasBin(args) ? parser.BINARY_EVENT : parser.EVENT (in both places) |
@darrachequesne Hi, I dont think that would work, as one of the main features of the hasBinary flag is so you can set it to true or false. Both options would override the hasBin function. If I had a large object containing a binary, the JSON flag wouldn't work as it does have a binary, so the HasBin function would then run, which I am trying to avoid. Also, the naming is less confusing if you use hasBinary, not JSON. Thanks |
@Andrews54757 Ok thanks, I understand. A few remarks though:
|
|
Doc looks good to me - Anyone disagree? :) |
@@ -545,6 +555,17 @@ io.on('connection', function(socket){ | |||
}); | |||
``` | |||
|
|||
#### Flag: 'hasBinary' | |||
|
|||
Specifies whether there is binary data in the data to send. Increases preformance when specified. Can be `true` or `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preformance -> performance
data to send -> emited data ?
@@ -327,6 +329,14 @@ Sets a modifier for a subsequent event emission that the event data may be lost | |||
io.volatile.emit('an event', { some: 'data' }); // the clients may or may not receive it | |||
``` | |||
|
|||
#### Flag: 'hasBinary' | |||
|
|||
Specifies whether there is binary data in the data to send. Increases preformance when specified. Can be `true` or `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preformance -> performance
data to send -> emited data ?
Thanks for the updates! I am still not convinced about the |
@darrachequesne Two minds about it - think something like containsBinary would be better - but I then feel that is too long. |
I personally like hasBinary better because it is short and concise. |
@darrachequesne How about I expand this further. So it would be |
However, I feel that it would be performance issue to check strings. Any ideas? |
Shame this wasn't merged. This single function is what is slowing my server down to a whole other level as i'm sending large JSON's. The I simply replaced all the code inside |
@wagenaartje Yes, I agree with you. Thats why I stopped using socket.io and built my own from scratch. |
Merged as #3185, sorry for the delay. |
The kind of change this PR does introduce
Current behaviour
When an object is emitted, the hasBin() function is used which iterates through the object checking for binary data. (https://github.com/socketio/has-binary)
New behaviour
The hasBinary flag allows for you to specify whether the object you emit has binary data or not, which skips the inefficient hasBin() function. You can now do
Other information (e.g. related issues)
I found out that I could make socket.io two times faster by implementing this. Since in many circumstances a developer would know when he/she will send binary data (or not), the performance can be drastically improved by providing this information. This is because without it, the HasBinary function will run, which itinerates through everything in a object to check for binary data. This is very inefficient with large objects. This new flag allows for developers to fix this problem.