pebbe / zmq4

A Go interface to ZeroMQ version 4
BSD 2-Clause "Simplified" License
1.18k stars 163 forks source link

Faster sendMessage() #71

Closed gallir closed 8 years ago

gallir commented 8 years ago

Avoid the double walkthrough and the creation and resizing of the slice.

gallir commented 8 years ago

The original function returns on the first error. The new version ignores all errors.

Oops. will fix and check it.

About the default case, it was strange to me but wanted to keep it as it was before in order no to broke anything.

gallir commented 8 years ago

I added the missing error checking, sorry :(

I left the default case for interfaces different to [][]byte and []string just because it was so in the original. I was testing during several hours and a few terabytes, didn't find any problem.

pebbe commented 8 years ago

I agree that the unflattening of the list is needlessly slow. But your solution ignores the problem that is solved with the falleting: the last argument could be []string or [][]byte with length zero, and then the argument before last should not use SNDMORE.

I will rewrite the code.

gallir commented 8 years ago

But your solution ignores the problem that is solved with the falleting: the last argument could be []string or [][]byte with length zero, and then the argument before last should not use SNDMORE.

WTF? It seems you even didn't read the long comment where I commented and ASKED about this issue:

if last1 < 0 && i0 == last0 { // A bug in the program?, kept for compatibility of the // previous version. // The program has sent an empty slice as last // argument. Force to send the message with no SNDMORE. // I'm (gallir) not sure if must be sent also a zero sized byte // array for intermediate empty slices partial, err = soc.sendSinglePart(dontwait, []byte{})

Read it again, specially "i was not sure" and "program bug" (several examples in ZeroMQ that send empty slices).

It's a problem of policy, what's an empty slice? O zero length frame or nothing at all? I didn't know what's the right one and was asking and notifying to you. But your answer was like "you don't care" while the solution is simply to pop last empty slices, as I did in our internal version keeping the rest of the code: https://gist.github.com/gallir/05be611db38c6beec310

Also, you didn't improve the function (even touched the file) for months and then used my same code just changing a few variable names (but keeping the same boilerplate as before), added the initial popping and rejected my pull request...

Great man, expect no more pull requests.

pebbe commented 8 years ago

Your code wasn't good enough. But it reminded me that I had to fix this issue. I didn't use your code.