6 ms·
I am shocked that PHP of all things has faster speed than python.
by humanistbot 4y ago
I am shocked that PHP of all things has faster speed than python.
- bityard 4y agoIt's not as surprising if you look at the primary use case of PHP. It takes a request, does a bunch of stuff, and returns the result to the web server. And it needs to do all of it before the user who clicked on the link gets bored and goes somewhere else. (Or the API client calling it times out...)
- coldtea 4y agoHow is that relevant? This is not about it being faster for "it's primary use case" (optimized for that, etc). It's generally faster than Python in doing the same things as Python does, unrelated to web too.
- lmm 4y agoThe point is that PHP's primary, original use case is latency-sensitive in a way that Python's isn't. So it's always been subject to more performance pressure.
- crote 4y agoI am not. PHP is traditionally used solely for websites. Some of those have grown rather large, to the point that having engineers optimize the language is cheaper than buying more servers. Python, on the other hand, is first and foremost a scripting language. When performance does matter, you often end up using a wrapper around a C library, like NumPy. This means there is relatively little money in optimizing the Python interpreter.
- DeathArrow 4y agoThere are websites and large scale software. Google uses Python for a lot of its products. It would seem sensible that since Facebook poured a lot of resources in optimizing PHP, Google would have done the same for Python. Also, Python is the first or second most popular language.
- fuckstick 4y ago> It would seem sensible that since Facebook poured a lot of resources in optimizing PHP Well they sort of half assed tried years ago - they employed GvR at one point. Then they gave up and they continue to lean heavily on C++, Java and there is thing they developed in the interim: Go. > Also, Python is the first or second most popular language Hogwash. For all the open source and other development that occurs and is “indexed” on internet discussion forums there is countless boring ass shit behind the scenes in sweatshops around the world and corporate back rooms. PHP, Java, and C# are still probably more popular to start.
- hnzix 4y agoCorporate has a faceless horde of Java devs.
- DeathArrow 4y agoLots of C#, too. And I specialized in C# since it seemed a little bit more enjoyable than Java at the time and the jobs were plenty. Of course, Java changed quite a bit since then so it might be more desirable than it was.
- dragonwriter 4y ago> For all the open source and other development that occurs and is “indexed” on internet discussion forums there is countless boring ass shit behind the scenes in sweatshops around the world and corporate back rooms. Much of which is also in Python.
- ivan23178 4y agoJS is also very popular. Not for the same things as Python but in some aspects it's becoming modern PHP (which is still popular, if maybe aging somewhat kinda like Perl). But Python is definitely very popular for new back room stuff (source: long digital sweatshop career)
- fuckstick 4y ago
- skybrian 4y agoIt can't be explained by lack of effort. There have been several serious attempts to make Python run faster, including one by some Google engineers. Many of them fail, and the ones that succeeded to some extent aren't mainstream. It's hard. For Python, the C integration probably makes things harder.
- habibur 4y agoInteresting how a language written solely for websites, beats others in their own game which isn't about websites.
- sottol 4y agoI think they did a lot of similar work to what python 3.11 did and more when releasing PHP7. I'm absolutely not in the loop but remember postings here on HN a few years ago. Meta/FB is also pretty invested in Hack (was once a php dialect, again, out of the loop), maybe they contributed a thing or two?
- tedivm 4y agophp7 was such a huge leap they skipped php6 (although there were other reasons for that).
- captn3m0 4y ago> Version 6 is generally associated with failure in the world of dynamic languages. PHP 6 was a failure; Perl 6 was a failure. It's actually associated with failure also outside the dynamic language world - MySQL 6 also existed but never released. TIL MySQL 6 https://wiki.php.net/rfc/php6 https://wiki.php.net/rfc/php6
- hashar 4y agoPHP 5 was kind of slow, to a point it threatened the future of Facebook (now Meta). They eventually went to transform it to CPP for speed improvement hiphop-cpp then went to build a VM with jit compilation. You could then deploy your app by transfering a sqlite file containing the compiled byte code. At Wikimedia we adopted it which has cut our CPU usage by half and has saved a few hundred of servers. We had some Facebook engineers helping which involved patching the Linux kernel while at it. Those were good times. Eventually PHP 7 followed up with a similar approach and had more or less the same performance as HHVM. Facebook went then to focus on the Hack language (a dialect of PHP with strong typing) and eventually phased out back compat with Zend. From what I remember, Sara Golemon at Facebook has done a lot of outreaching to Open Source project and gave us a lot of assistance (as well as others at Facebook).
- booi 4y agoPHP has always been very fast of the untyped scripting languages even from the web 1.0 days.
- kstrauser 4y agoThat doesn't relate to Python, though.
- nerpderp82 4y agoClearly we need a Python to PHP transpiler (trigger word) so we can be webscale (trigger word).
- captn3m0 4y agoPHP typically beats Python on CPU bound benchmarks: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php-python3.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... (Measures Python 3.10.4 against PHP 8.1.5 - so expecting these to change a bit).
- coldtea 4y agoPHP has always been several times faster than Python. Even more so with the speed updates post 7.
- treeman79 4y agoBack around 2003 I was hosting an internal web app for a fortune 50 company in python. It could handle 2 users at a time. I rewrote it in PHP. Scaled to hundreds with trivial work. Probably could have handled far more.
- pphysch 4y agoThe key here is that you rewrote the whole thing. The old and new languages isn't as relevant.
- talideon 4y agoPHP 5 and onwards have had a lot of resources put int o making it fast. The surprise for me is how close Python is getting to closing that gap.
- throwaway894345 4y agoFacebook dumped a ton of effort into making PHP fast over the last couple of decades. No one has been able to make Python especially fast without breaking compatibility with important libraries (Python exposed virtually the entire interpreter as its extension surface, and since Python is so slow, extensions are a major part of the ecosystem as they're the main way to recoup performance, which in turn means that changing the extension interface to make things faster would break a bunch of the ecosystem, and the Python maintainers are pretty scarred after the 2->3 breaking changes). Pypy comes close, and it has been grinding away to get compatibility, but last I checked you still couldn't so much as talk to a Postgres database through a reputable package.
- depr 4y agoThe last couple of decades? Facebook is not even two decades old. And they turned it into their own language.
- throwaway894345 4y agoYeah, it was a crude estimate. Call it 10-15 years if you want.
- toast0 4y agoPHP itself is pretty fast. It's the things that people do in PHP that get slow. Most of the Yahoo frontends were rebuilt in PHP in 200x because it was fast enough and much more usable than the thing they used before(trigger warning: hf2k) Of course, people then go and build up sculptures of objects that will be thrown away after every request, and that stuff makes everything slow (that style of code is why PHP wasn't good enough for Facebook, IMHO), but you can build trash sculpture in any language.
- mgkimsal 4y ago100% not shocked at all. I recall a couple of times over the past 15-20 years where a current python significantly outperformed a current php version, but my recollection is that php was usually a bit faster, or sometimes a lot faster. PHP 7 was released on dec 2015, and gained significant speed bumps and better memory usage, with the average php execution time being cut in half, or more, generally without any code change whatsoever. It was quite remarkable. The path from 7.x-8.1 so far has generally seen incremental speed bumps again - usually somewhere between 3-8% improvements per release. Obviously this is going to be dependent on use cases, but overall it's been a fairly steady set of speed improvements over the last 7 years.
- GlitchMr 4y agoPHP is a much simpler language which helps a lot with optimizations. For instance, consider something like property access. In PHP, doing `$a->b` accesses field `b` of object `$a`. The implementation is essentially type check (making sure `$a` is an object) and hash table lookup. If this fails, then it calls `__get` method if it exists. In Python on the other hand, `a.b` involves `__getattr__`, `__getattribute__`, `__mro__`, `__get__`, `__set__`, `__delete__` and `__dict__`. Here is a description of how the attribute access works: https://docs.python.org/3/howto/descriptor.html#overview-of-descriptor-invocation https://docs.python.org/3/howto/descriptor.html#overview-of-....