6 ms·
Similar logic applies server side too. If your backend is inefficient then you may well be consuming orders of magnitude more power per query. While I take thes
by pacaro 7y ago
Similar logic applies server side too. If your backend is inefficient then you may well be consuming orders of magnitude more power per query. While I take these numbers with more than a pinch of salt, I've seen comparisons that suggest that a backend written in ruby/python/php may be over 10x less efficient than one written in Java/C++
- sieabahlpark 7y agoWhen you can be just as productive as a web developer in c++ let me know.
- pacaro 7y agoIndeed, there are many factors to consider here. In a sense that is what makes discussions like this interesting! I suspect that in some respects that we already optimize for this as an industry, we might have application logic in python, but the database is presumably written in a systems programming language.
- luckylion 7y agoFair point. I believe productivity is a major factor in most performance issues. Write highly optimized code that's very fast and as small as possible or pull in jquery and a dozen libraries? It's pretty obvious which one will get the job done more quickly. And once the job is done, optimization often is off the table, because the next features await. I work for clients that are making lots of money with their sites, and not even then are they willing to spend pennies on the dollar to optimize those pages. Maybe the highest impact you can get is working on most-used parts. Make Wordpress run 3% more efficiently and you'll have an enormous global impact. Make your own site run 3% more efficiently and it won't register globally, unless you're Google, FB etc.
- de_watcher 7y agoIt's just good developers are hard to find. Web gurus will tell you that web is slow because the specific sites are written badly. While Linus has told that C keeps bad developers away from the kernel.
- guessmyname 7y ago> When you can be just as productive as a web developer in c++ let me know. I used to work at OkCupid. The entire web application is written in C++ [1] and I was quite proficient with the language even before joining the company. Then I joined a medium sized game studio where C++ was also the most common language, and as you can guess we also decided to built the game landing pages and user management system using C++ with Boost and an in-house template system. I am not OP but you asked to let you know if someone is a productive web developer in C++, well, I am. [1] https://github.com/OkCupid/okws https://github.com/OkCupid/okws
- okaleniuk 7y agoLet's skip this and go right to web development in assembly: https://board.asm32.info/ https://board.asm32.info/ The author claims that it's only twice less productive to write in assembly than in high-level languages. But the performance gains are overwhelming so it might very well pay back the effort.
- mr__y 7y agoAssembly? Thats for amateurs, we should move right to FPGAs
- vardump 7y agoTo cut this short (own silicon, sand, etc.), we should just create a universe first. FPGAs are fun, though. Saving 12 microseconds (assuming gigabit and "standard" frame sizes) of latency by sending ethernet frames (that contains frame data CRC!) before you even have all of the data to send and then modifying data at the end of frame to match with whatever CRC we sent ~12000 bit times (= 12 microseconds) before.
- mr__y 7y agoThat seems extremely interesting to me! Would you care to tell any details about that or is it covered by NDA? I'm guessing that's something HFT related?
- vardump 7y agoThis was just for fun (tm). I know HFT guys pull of tricks like these, but no, this is either not difficult to pull off on an FPGA nor is there any NDA. Easy if you send UDP with checksums off or raw ethernet frames. Receiving party will of course need to ignore the last 4 bytes needed to make the CRC computation correct. Would be interesting if anyone managed to do this with TCP. If it's even possible to get both TCP and ethernet frame FEC match in real time and ideally somehow even mask the data from the recipient. Probably not possible, but... who knows.
- pjmlp 7y agoIt is a matter of tooling. Using something like C++ Builder with its Internet VCL component libraries it is hardly any different from using Java or .NET stacks for Web development.
- pjc50 7y agoI've been a professional C++ developer for years and I absolutely would not do this. The security risks are just too high, not to mention the build times. I'd probably default to C#, which can be decently fast and has a managed runtime.
- okaleniuk 7y agoIt's really not about languages. Your code has to be perfect or trivial for the language to matter. If it's easier for you to write better algorithms in Python than in C++, than your code will probably be faster while written in Python. Because better algorithms will easily get you further than 10x in terms of performance.
- pacaro 7y agoAgreed. A good point that people often miss. We also are often in constant pursuit of the next feature, so don't have the luxury of the kinds of polishing or optimization that might get some of those real performance gains. I was a big fan of the accidentally quadratic tumblr. It's important to remember though that not all significant performance gains come from better algorithms, I've taken an industry standard C implementation of an algorithm and improved perf (as measured on production workloads) by 30x by thinking about issues that didn't really concern the original author (in particular cache locality and realizing that the entire problem could be moved into the integer domain)
- jcelerier 7y ago> If it's easier for you to write better algorithms in Python than in C++, than your code will probably be faster while written in Python. Because better algorithms will easily get you further than 10x in terms of performance. In practice I have not often seen this pan out - if you've got the most common case of a GUI app with tons of callbacks which update your UI in real-time, there isn't one algorithm to optimize anywhere, but instead you die a death of a thousand cuts because each callback will be marginally slower than what it would have been in C++. Also, it's much easier to control allocations & system calls in C++ (or other native languages for what it's worth) than in Python - and in my experience preventing those is an even better pathway to getting frames rendered in less than 5 milliseconds (which is what you want to do if you have any respect for your 144hz-screen users)
- nostrademons 7y agoI've rarely found that GUI code is ever the bottleneck. Usually it's only a problem for mousemove handlers and code that runs directly in the event loop. Most GUI apps don't even have those, unless you're writing a game. The big problem with Python GUIs is usually that the GUI framework is often written in Python. (Or it's that things like network & parsing code gets written in Python.) The framework does a lot more heavy lifting than the app does - in particular, it's responsible for converting the system events into clicks, drag&drops, submissions, etc. for the app, and for rendering components into bitmaps. If the framework is written in C++ and just exposes a Python API, there's no problem. That's how wxPython and PyQT do it.
- misterman101 7y agoThe difference is that the company is not paying (and therefore not tracking costs) for client code, so it has less incentive to fix things. The extra engineers needed to make a Java/C++ backend need to eat/sleep/consume and have their own environmental cost. $$$ is a good first-order proxy of environmental cost, and lower server costs probably don't make up for engineering salaries.
- pacaro 7y agoYeah, this is a good analysis, there are a handful of companies where performance savings in critical services will cross those thresholds, but for everyone else it's simply theoretical. Unfortunately there are a lot of those "everyone else" services out there so it becomes a death through a thousand cuts concern. Obviously from an environmental perspective (if that is the ethical concern in question) there are probably higher priorities
- TeMPOraL 7y ago> The extra engineers needed to make a Java/C++ backend need to eat/sleep/consume and have their own environmental cost. Engineers are not VMs in the cloud, you don't provision them on demand. They exist as human beings, and eat, sleep and consume anyway. > $$$ is a good first-order proxy of environmental cost, and lower server costs probably don't make up for engineering salaries. If you run it through a heavy low-pass filter to remove all the sales-related price shenanigans. And discount salaries, because taking on an engineer at $X doesn't mean you've just increased your carbon footprint by $X. You could actually see how taking into account salaries might be a cause of the problem. Say you can hire an engineer who'll get you a basic backend working in Python or Ruby for $100k, or an engineer who'll get you that backend in a more efficient stack - say C++ or Java, or even a more polyglot solution with hotspots optimized - for $150k. In the first case, your yearly costs of cloud servers are $20k, in the latter $5k, reflecting the 5x efficiency difference. From the monetary point of view, you should take the less efficient option - after all, you're getting $35k ahead. From the environmental point of view, your service uses 5x the energy it should. And you're not the only company with this dilemma. If everyone chooses the cheaper option, then the whole segment of industry becomes 5x less efficient than it should be.
- deleted 7y ago
- danielscrubs 7y agoI wouldn’t group Java and C++ together like that. Java is faster than JS but let’s not kid ourselves.
- mr__y 7y agoWhile not trying to defend PHP (well, tbh I'm trying but just a little), but there is a phalcon framework ( https://phalconphp.com/ https://phalconphp.com/ ) which is written in C and works as a PHP Extension. While the rest of the code still is in PHP, at least the framework bits including a lot of boilerplate are much faster that way.
- noir_lord 7y agoPretty broad, if we assume that cpu time is the same algorithms running on the same hardware then PHP is faster than both Python and ruby. However the framework definitely matters here, PHP’s build the world and destroy it on every request makes a big difference.
- Nyandalized 7y agoMost web tasks are completely I/O bound anyway, the significance in making the few business logic decisions is minimal.
- tremon 7y agoI have seen plenty of web tasks that should be I/O bound, but were not because of inefficient coding. It's not the business logic, but the post-processing performed by devs that don't know how to write proper database queries(or designs) that costs power. My favourite example: slurping an entire category table on each page load and then using an O(n^2) loop to rebuild the navigation tree. On a cold cache, they had request times (server-side) of 7 seconds. Rewriting to a recursive CTE brought the page load time (client-side) down to below 100 ms, even on a cold cache.