4 ms·
In https://github.com/alexhultman/uWebSockets/blob/master/src/uWS.cpp https://github.com/alexhultman/uWebSockets/blob/master/src/u... What's the deal with del
by justsaysmthng 10y ago
In https://github.com/alexhultman/uWebSockets/blob/master/src/uWS.cpp https://github.com/alexhultman/uWebSockets/blob/master/src/u...
What's the deal with
delete [] (char *) head;
where `head` is of type `struct Message` ? Is this some kind of performance trick ?... Otherwise it looks kind of suspicious..
- hendzen 10y agoyeah - the C++ bits were clearly written by someone who doesn't know the language well. I'd be careful about using this code in production. EDIT: Specifically I'm referring to the usage of raw pointers, unchecked pointer arithmetic, goto for flow control and raw new/delete calls. The author says they have run tests under valgrind, but that doesn't say anything unless the inputs were malicious. Ideally it should be compiled with ASAN and run under something like afl-fuzz. Also - why do you take a libuv dependency - then use uv_poll_t directly with raw send/recv calls instead of using uv's provided TCP primitives?
- alexhultman 10y agoIf you allocate the buffer as a char * you should delete it as a char *. Thank you for the kind words.
- alexhultman 10y agoAlso - this server passes the entire Autobahn with no fails, passes Engine.IO tests, Primus tests and exits gracefully with no Valgrind issues. Also, it builds with no warnings. Also, it has been running for weeks stable.
- IIlllIllIIIIlII 10y agoCan I ask why you choose to implement your own queue when many exist within C++? (e.g. using queue<T> or list<T>)
- alexhultman 10y agoMemory footprint and performance. This implementation is way, way more lightweight. And it assumes that the buffer being queued has a struct Message in its head, so it doesn't have to allocate a node - one memory allocation is therefore skipped.
- alexhultman 10y ago1. It has been compiled with ASAN. 2. What you suggest would blow the memory footprint 16x. Thanks for giving your infinite enlightenment, after looking at my code for 10 minutes. I guess your 10 minutes of reading the code is infinitely much more valuable than my 3 months work on it? Get over yourself.
- ddlerk 10y agoIf you want people to take you and your projects seriously, you are going to have to stop being so antagonistic. I've seen you act this way here, on Reddit, and on GitHub... The sarcasm, childish comments, and resorting to insults the second someone criticizes your code isn't giving me any hope that you can competently maintain a project like this. Take a look over the HN Guidelines [1] and the "Approach to comments"[2] sections of the site. [1] https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html [2] https://news.ycombinator.com/newswelcome.html https://news.ycombinator.com/newswelcome.html
- Klathmon 10y agoThere's no need to resort to insults in-reply to questions or criticisms. It's a valid question (that i think you did answer, but not very well). Dropping to very unsafe "lower levels" should only be done when absolutely necessary as a single mistake here could cause massive security issues.
- smt88 10y agoHumility and a collaborative attitude are really important to get the best results. When people attack your code, it isn't an attack on you. It makes your code better. It's one of the downsides to releasing any opinionated project (and many good projects are opinionated). For my part, I won't use software written by someone who doesn't either refute criticism or use it to improve code, and I'm not satisfied you're doing either of those.
- alexhultman 10y agoAccording to logic, this quote "yeah - the C++ bits were clearly written by someone who doesn't know the language well. I'd be careful about using this code in production." is a personal attack. I get offended by this, personally. When I get offended, personally, I answer how ever I see fit. Thank you, you will be missed. I don't know what to do without you.
- babuskov 10y ago> usage of raw pointers, unchecked pointer arithmetic, goto for flow control and raw new/delete calls But without all that you would lose performance which seems to be the main goal of this project.
- alexhultman 10y agoYes, I use uv_poll_t instead of uv_tcp_t because of massive memory and performance differences. Every decision made, has been made from a performance perspective.
- infamouscow 10y agoI'm interested in what you've learned using libuv while tuning this library. I've read in the past that libuv makes a lot of unnecessary memory allocations. Is this true and/or have you consider writing directly to select/epoll/kqueue? Is there a lot of overhead in using libuv vs the OS provided eventing syscalls?
- alexhultman 10y agoLibuv is definitely not as "screamingly fast" as it's marketing tells. I found the biggest flaw with libuv to be the uv_tcp_t which forces you to have a user space buffer to receive the data, something not needed when using uv_poll_t. I do not know what the overhead of uv_poll_t is compared to epoll/kqueue but I think it's a good balance to depend on libuv in this case, and since we need to integrate with Node.js it is kind of required. I would much rather use mTCP to further improve the performance but then this project would not be as relevant to most developers. Performance & relevance is key - it can be optimized further by using mTCP and such.
- jacobwcarlson 10y agoThere are many improvements that could be made to this code. However the developer is extremely antagonistic and unwilling to accept criticism so I doubt that the issues will ever be fixed.
- babuskov 10y agoNot sure if that's wrong, but it seems that the program would crash if you call pop() on an empty Queue? I guess it never happens in this particular program, which I assume was the reason to squeeze even more performance.
- alexhultman 10y agoYes it would cause undefined behavior but empty() is checked before popping.