News for hackers. Stuff that matters.
Re:The Ethics of Web Performance by pacaro on Thursday August 01, 2019 @02:16AM (#20581393)
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++
Re:The Ethics of Web Performance by okaleniuk on Thursday August 01, 2019 @02:29AM (#20581441)
It'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.

Re:The Ethics of Web Performance by jcelerier on Thursday August 01, 2019 @02:49AM (#20581537)
> 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)

Re:The Ethics of Web Performance by nostrademons on Thursday August 01, 2019 @03:06AM (#20581621)
I'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.

Re:The Ethics of Web Performance by okaleniuk on Thursday August 01, 2019 @03:31AM (#20581780)
Well, yes. GUI usually don't require much algorithmic work so there's just not much space to loose performance because of bad algorithms.

But I've seen researchers been vastly prolific in Python. They make segmentation or registration algorithms that beet the market, and then they call us (C++ engineers) to make them "fast". Usually we do, since we're trained for that. But it's never orders of magnitude. It's like 2-3 times faster.

And there were even cases where the C++ code appeared slower in the end. Well, we use slightly different math core than the numpy does and sometimes they're doing worse.

Re:The Ethics of Web Performance by TeMPOraL on Thursday August 01, 2019 @04:03AM (#20581945)
The cases you're describing sound like cases where Python is cheating. The thing that allows Python to even be considered useful for any kind of heavier computing is that a lot of standard/popular libraries are FFI wrappers to C code.

It's an excellent deal for scientific computing, where your logic is trivial and almost all work is done in C. But it's not so rosy for user-facing applications, where it's the logic that dominates.

Re:The Ethics of Web Performance by dodobirdlord on Thursday August 01, 2019 @11:38AM (#20584782)
> Python is cheating

Weird to call it cheating when Python's strong intertop with C is a specific design goal of the language.

Re:The Ethics of Web Performance by TeMPOraL on Thursday August 01, 2019 @12:33PM (#20585493)
It's tongue-in-cheek. And also a little bit of jealousy; I wish Common Lisp felt a little less fragile around binding generation and package distribution - then I could have a high-level language that's almost as fast as C (when using SBCL implementation), that could still interface with even faster C code.
Re:The Ethics of Web Performance by nostrademons on Thursday August 01, 2019 @02:57AM (#20581580)
Only if you're sure that the particular algorithm you're working on is the bottleneck.

One particularly common performance pessimization is replacing an algorithm with one that has better big-O performance but a worse constant factor, and doing so where the particular O is much smaller than the number of times the function is called. People learn that hashmaps are O(1) while red-black trees are O(log N) and linear search is O(N), so they'll default to using a hashmap for a lookup table, even if the lookup table has 10 items but the keys are ~500 byte strings. (I'm guilty of this one myself, but at least I measured and fixed it.) Then they'll call this lookup in a loop 5000 times.

Using Python or another rapid-prototyping language can be a good idea here if you take the time to profile and identify the bottlenecks, but very frequently you end up shipping it, throwing hardware at it, and then wondering why you're spending hundreds of thousands of dollars on AWS bills. Plus, a really big problem with many common Python architectures is that they use pure Python libraries & frameworks even on the critical path. (Big offenders here include using BeautifulSoup in your 1B-page web analysis or Django on your million-user website.)

Re:The Ethics of Web Performance by hinkley on Thursday August 01, 2019 @04:27AM (#20582077)
Something I made the mistake of saying in interviews for a bit, but now save for beers, is that often the 'hardest part' of the project is cleaning up all of these constant factor bits. They're thankless. They're everywhere, and at some point your flame chart looks pretty damned flat. There are no big wins anymore. It's fighting for inches.

(really the 'hardest thing' about software is all of the things that are true but few believes are important. Dropping the Big O can be proven empirically)

Re:The Ethics of Web Performance by okaleniuk on Thursday August 01, 2019 @03:16AM (#20581693)
Yes, that's all true.

Regarding the algorithms on small data, I even made a quiz about that: https://wordsandbuttons.online/challenge_your_performance_in...

Of course, Python or C++, if you want performance, you should design with performance in mind. Measurements and profiling are implied.

Re:The Ethics of Web Performance by pacaro on Thursday August 01, 2019 @02:36AM (#20581485)
Agreed. 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)

Re:The Ethics of Web Performance by pradn on Thursday August 01, 2019 @12:55PM (#20585770)
Most apps don't have heavy-weight algorithms that benefit from big-O optimization. So, performance is decided by the speed of common language elements (function calls, memory allocations). It will be more effort, and harder to make secure, but you will most likely see a performance gain when using a systems language. And even more so, C++ has more escape hatches (custom memory allocators, multi-threading) than Python.
Re:The Ethics of Web Performance by meuk on Thursday August 01, 2019 @03:11AM (#20581656)
I always saw the tradeoff more in terms of developer time: Python is faster to write but pretty much always slower to run (unless you're doing a lot of IO or mainly writing wrapper functions around compute-intensive compiled code).

I don't think a lot of people would actually use asymptotically slower algorithms when using a different language.

Re:The Ethics of Web Performance by danielscrubs on Thursday August 01, 2019 @03:05AM (#20581619)
Nice! Go write that web framework and let’s benchmark that.
Re:The Ethics of Web Performance by okaleniuk on Thursday August 01, 2019 @03:24AM (#20581732)
I actually thought about that. Not a framework but an ultra-efficient web-server. Going reductionist, a static serving web-server is just a key-value storage accessible via HTTP.

So I can run a Python script that gathers all the key-value pairs (names and pages), makes an optimized search tree out of them and spawns is out as an LLVM sheet of code. Then I only have to embed it into a trivial HTTP "answering machine", assemble it all under the target architecture as part of the deployment - and that's it.

I have more fun things to do right now, but my hosting contract expires in a year or so so I'd look for the alternatives by then.

Re:The Ethics of Web Performance by pjc50 on Thursday August 01, 2019 @05:00AM (#20582226)
> ultra-efficient web-server.

There are a lot of these already. Serving static content quickly is not an interesting challenge any more, most of them will be able to saturate a 10GBE link over a huge number of connections. No, all the interesting effort is in dynamically assembling pages.

Re:The Ethics of Web Performance by mr__y on Thursday August 01, 2019 @03:21AM (#20581718)
While not trying to defend PHP (well, tbh I'm trying but just a little), but there is a phalcon framework ( 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.
Re:The Ethics of Web Performance by misterman101 on Thursday August 01, 2019 @02:32AM (#20581463)
The 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.

Re:The Ethics of Web Performance by TeMPOraL on Thursday August 01, 2019 @03:24AM (#20581728)
> 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.

Re:The Ethics of Web Performance by pacaro on Thursday August 01, 2019 @02:51AM (#20581545)
Yeah, 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

Re:The Ethics of Web Performance by brlewis on Thursday August 01, 2019 @08:18AM (#20583092)
> The 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 incentive is there whether the company recognizes it or not. A price your customers pay matters to your business.

Re:The Ethics of Web Performance by noir_lord on Thursday August 01, 2019 @03:24AM (#20581725)
Pretty 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.

Re:The Ethics of Web Performance by Nyandalized on Thursday August 01, 2019 @04:55AM (#20582212)
Most web tasks are completely I/O bound anyway, the significance in making the few business logic decisions is minimal.
Re:The Ethics of Web Performance by tremon on Thursday August 01, 2019 @05:51AM (#20582436)
I 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.

Re:The Ethics of Web Performance by danielscrubs on Thursday August 01, 2019 @02:58AM (#20581586)
I wouldn’t group Java and C++ together like that.

Java is faster than JS but let’s not kid ourselves.

Re:The Ethics of Web Performance by sieabahlpark on Thursday August 01, 2019 @02:25AM (#20581419)
When you can be just as productive as a web developer in c++ let me know.
Re:The Ethics of Web Performance by guessmyname on Thursday August 01, 2019 @02:36AM (#20581488)
> 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

Re:The Ethics of Web Performance by okaleniuk on Thursday August 01, 2019 @02:40AM (#20581506)
Let's skip this and go right to web development in assembly:

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.

Re:The Ethics of Web Performance by mr__y on Thursday August 01, 2019 @03:25AM (#20581738)
Assembly? Thats for amateurs, we should move right to FPGAs
Re:The Ethics of Web Performance by vardump on Thursday August 01, 2019 @03:55AM (#20581903)
To 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.

Re:The Ethics of Web Performance by mr__y on Thursday August 01, 2019 @09:31AM (#20583515)
That 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?
Re:The Ethics of Web Performance by vardump on Thursday August 01, 2019 @10:58AM (#20584280)
This 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.

Re:The Ethics of Web Performance by luckylion on Thursday August 01, 2019 @02:33AM (#20581465)
Fair 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.

Re:The Ethics of Web Performance by de_watcher on Thursday August 01, 2019 @02:35AM (#20581479)
It'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.

Re:The Ethics of Web Performance by pjmlp on Thursday August 01, 2019 @02:48AM (#20581529)
It 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.

Re:The Ethics of Web Performance by pacaro on Thursday August 01, 2019 @02:29AM (#20581447)
Indeed, 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.

Re:The Ethics of Web Performance by pjc50 on Thursday August 01, 2019 @05:37AM (#20582381)
I'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.