Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I am shocked that PHP of all things has faster speed than python.


I 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.


There 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.


> 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.


> 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.


I mean, sure, but I’m just saying point me to a source that is ranking Python as #1 or #2 most popular. If it’s TIOBE or something similar it’s meaningless.

I say this as someone that has made their career mostly on the “top 5” TIOBE languages - but that ranking is a bunch of crap for the overall commercial software world.

C? Give me a fucking break. Never in 20 years have I known there to be more C than Java jobs.

And now everyone and their dog including doctors and other non tech-savvy professionals are doing Intro to Python courses (and then never touching it again) so they too can feel like they know something about ML or stats. Lot of noise.


>I mean, sure, but I’m just saying point me to a source that is ranking Python as #1 or #2 most popular. If it’s TIOBE or something similar it’s meaningless.

According to 2022 Stack Overflow developer survey, if we exclude HTML, SQL and Bash, top five languages (as in being used by most developers) are: Javascript, Python, Typescript, Java and C#.


https://madnight.github.io/githut/#/pushes/

Checking here, if we go by pushes on GitHub, JS, Python, Ruby, Java, PHP are the top for 2021.

This is of course biased to only stuff on GitHu band public (assuming, but doubt they're publishing private data on BigQuery).

No idea how much of that is pet projects vs production of course.


JS 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)


Corporate has a faceless horde of Java devs.


Lots 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.


> Python is the first or second most popular language.

By what metrics? Redmond quarterly from June shows Python at #2, and PHP at #4.

https://redmonk.com/sogrady/2022/10/20/language-rankings-6-2...


Most metrics. Tiobe, Redmonk, Pypl, Stack Overflow survey. Top 10 and even top 5 is generally the same, the order might differ a bit.

I've looked at various sources since the last 5 years and not much changed. I hoped some languages like Nim, Crystal or Zig would pick up a bit of steam, but no.

Go and Rust moved up a bit and now seem safer bets to invest some time into.


> > Python is the first or second most popular language.

> By what metrics?

Hmm, why don’t you answer your own question?

> Redmond quarterly from June shows Python at #2,

That clearly is one that puts it “first or second”, yes.


Yes, it was partially an answer, and it's not saying Python isn't high up.

But still wanted to know by what metrics the GP was making their claim.


Instagram is a Django website (Django is a Python web framework).


It 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.


Interesting how a language written solely for websites, beats others in their own game which isn't about websites.


PHP 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-....


PHP typically beats Python on CPU bound benchmarks: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

(Measures Python 3.10.4 against PHP 8.1.5 - so expecting these to change a bit).


Facebook 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.


The last couple of decades? Facebook is not even two decades old. And they turned it into their own language.


Yeah, it was a crude estimate. Call it 10-15 years if you want.


It'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...)


How 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.


The 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.


I 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?


PHP 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).


> PHP 5 was kind of slow

I remember it being slower than PHP4 for a while


php7 was such a huge leap they skipped php6 (although there were other reasons for that).


> 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


Whereas Python doesn't even plan for 4 because 3 hurt so bad


Meanwhile Java(ECMA)Script bucking the trend by getting its failure out of the way at 4.


PHP has always been several times faster than Python. Even more so with the speed updates post 7.


100% 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.


Clearly we need a Python to PHP transpiler (trigger word) so we can be webscale (trigger word).


PHP has always been very fast of the untyped scripting languages even from the web 1.0 days.


That doesn't relate to Python, though.


PHP 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.


Back 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.


The key here is that you rewrote the whole thing. The old and new languages isn't as relevant.


PHP 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: