IXWebSocket icon indicating copy to clipboard operation
IXWebSocket copied to clipboard

Get rid of double indirection

Open marton78 opened this issue 1 year ago • 2 comments

Hi, first of all thanks for this great library.

One hint: you could get rid of the double indirection in

using OnMessageCallback = std::function<void(const WebSocketMessagePtr&)>;

by changing it to

using OnMessageCallback = std::function<void(const WebSocketMessage&)>;

This could also be done in a backwards-compatible fashion by offering a second overload, e.g.:

using OnMessageCallbackNew = std::function<void(const WebSocketMessage&)>;
void setOnMessageCallback(const OnMessageCallbackNew& callback);

marton78 avatar Dec 19 '24 15:12 marton78

PS: I just saw that WebSocketMessage contains a const std::string& str, that's QUADRUPLE indirection (a pointer to the string, and therein a pointer to the string's contents).

marton78 avatar Dec 19 '24 15:12 marton78

Did you try to change to

using OnMessageCallback = std::function<void(const WebSocketMessage&)>;

What I do remember is trying real hard to avoid all thread races. But I might have tried a pointer for speedup, which could have been a bad idea.

I had written something called autoroute which was meant to be a benchmark -> https://github.com/bsergean/autoroute it would be nice to bench your new solution.

bsergean avatar Jan 23 '25 07:01 bsergean