317 points · by UkiahSmith · 7y ago · 183 comments
I believe their plan is to emit low-level code directly via DynAsm, without their own intermediate representation.
This kind of approach has been tried again and again and again and every project doing this either not got the results they wanted and given up or has had to go back and add a proper intermediate representation.
Examples include Rust adding MIR before emitting LLVM, Rubinius trying to emit LLVM directly from Ruby and not getting good results so giving up, JRuby adding an IR before emitting Java byte code, Dropbox's Pyston implementation of Python that emitted LLVM directly where they gave up entirely, etc, etc, etc.
Low level backends are not going to do the kind of key optimisations such as scalar replacement of aggregates that are table stakes for making a dynamic language perform well - they just don't have the high-level semantic model of the language needed to do it.
Maybe they've got some new ideas, or maybe simplicity is a key constraint for them, but I predict from experience that they will need an intermediate representation to get the results that they want.
These opcodes are used for optimizations and cached for the lifetime of the PHP process (across multiple requests).
Lower level bytecode lacks these higher level references (it usually has a lot of indices that index into raw lookup tables, but no real symbols that refer to results of computations and other variables).
Can you point me to some paper/reference about this? AFAIK it doesn't matter whether you have an AST or bytecode. Optimizations are done on an IR anyways.
That’s how I’ve always see “AST” used, but not the following:
yet can express the required data flows and dependencies so the trivial substitutions/replacements/caching and refactorings can be done at this level.
Is what you describe some flavor of ‘augmented’ AST? Does that have a name other than AST?
Perhaps the advantage here is that PHP really all that dynamic. PHP is much closer in design to taking Java and compiling it on every request than it is like Python or Ruby.
$moo = "hello";
$zork = "moo";
echo $$zork; // hello
It doesn't get much more dynamic than that.Although PHP does support the above syntax, it's actually pretty rare in production code. PHP can be optimized like JavaScript is: perform direct variable/member access but provide a slow path for these kinds of dynamic lookups.
The _get and _set magic methods (called when getting/setting missing properties) are quite common especially for frameworks.
> use DynAsm (developed for LuaJIT project) for generation of native code
But at the very least, this exercise will ensure that DynAsm will be actively used by a few people. So even if this PHP JIT effort fails, the underlying JIT technology will be more widely understood and hopefully better documented for other projects.
Can u give an example or link to a relevant article. Context: my area is more of high-level program (e.g. shape) analysis
Removing the object allocation saves time and puts less pressure on the GC. Replacing the instance variables with local variables may also allow the compiler to optimize some things that it would not have attempted to optimize before. For example, storing them on machine registers.
Ideal is also a classic https://www.oracle.com/technetwork/java/javase/tech/c2-ir95-....
The way I see it was PHP captured the vector of change, and left ample room for future developments. Both internal changes (hello, bytecode; hello, JIT), language level features (hi there, namespaces), and runtime level features (oh hai, countless built in classes and functions).
Moreover, unlike many framework that shone brightly and burned out quickly (Rails?), PHP captured the essence of the environment: HTTP is stateless, and URLs aren't uniformly routable from either end, and well-formed HTML/XML/JSON is just a subset of tag soup.
Worse is better.
But to me, one of the most significant advantages PHP has is that its documentation is terrific. PHP.net is simple, clear about parameters and return values (as clear as PHP lets it be anyways) and best of all has a terrific comments / examples section for each function.
Better documented is better.
In fact I remember a few occasions where I’ve ended up going by the advice of the comments rather than the documentation itself because the documentation was either out dated or just plain wrong.
As for the comments. Yes. But at least they're there, and quite often helpful. Plenty of times I've read other docs where I wished they had commenting but alas didn't.
That's a good observation. Because the mod_php and mod_perl Apache modules were much faster and lighter weight than CGI-BIN, and pre-installed on shared hosting, both PHP and Perl dominated the early web days.
Birds are Cats.
See, we can all make unsubstantiated claims.
Just one reason is enough. I personally disagree, I think it's great.
asp locked you into microsoft, jsp was laden with heavy/expensive java app servers and semantics, and coldfusion was a paid product (and eventually locked you into macromedia/adobe).
i think that if coldfusion had the same free+paid model as php, it would have taken the place of php in web history. despite its faults (maintenance and performance, for example), it was easier and faster to learn and matched the mental model of beginners, just like html itself.
ASP 1.0 was released in 1996. The first Cold Fusion in 1995. JSP not until 1998.
Cold Fusion and PHP appear to be neck-and-neck, almost; it's plausible that if Cold Fusion had been free, it might have taken more mind share away from PHP.
Interpolating results into HTML dynamically isn't an idea that originated with any of this software. Prior art is the shell "here document", also implemented by imitation in Perl and other languages. "Here documents" were used in CGI scripting before PHP. (I'm not saying that the shell's "here document" is the ultimate prior art, either).
At your system prompt:
$ cat <<!
<table>
$(for x in 1 2 3; do echo " <tr><td>$x</td></tr>" ; done)
</table>
!
<table>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
</table>I was talking to some kid who wanted to be a developer, and I echoed this sentiment. A complex tool with good documentation is easier to use than a simple tool with bad documentation.
What I dislike about it is the comments that every page includes. Most of them are very poorly written snippets of code from 15 years ago.
If you dislike those comments too, consider adding this to your ad blocker:
php.net###usernotesIt is also one of the few choices available on cheap shared hosting sites.
In a previous site of mine i had the entire site be statically generated but needed some server-side stuff in one of the pages, so i put something like %%PHPCODEHERE%% and modified the script that built the site to replace the %%PHPCODEHERE%% with the contents of a .php script.
PHP is the VBA of the web: it's ugly but too useful to ignore.
The only reason I use php for my own sites is because I don't want to administer any server and I don't want to be tied to a provider.
PHP is a good fit for this, because it's available at practically all cheap hosting providers (I don't need to administer the server with shared hosting) and I'm not tied to a single provider, because I can switch to an other hosting provider without too much effort.
With other langauges I either have to manage my own VPS (I don't want to pay for managed VPS), or I'm tied to a provider (Appengine, etc.).
I just kept using Java, .NET and C++, while enjoying their performance, IDE tooling, and whatever ideas they could bring into their web stacks.
Nowadays most cool companies that were pushing Ruby, are on JVM languages.
I think the staying power of php is at least in part due to the continued success of popular projects that rely on it, whoever was responsible for its initial successes.
A handful of projects really are the driving reason for PHP's ubiquity.
Wordpress/Joomla, phpBB/Invision/vBulletin, Magento...
The demand for support for these and some smaller and similar projects really drove webhosts to need to support PHP, and for a lot of the standardized tooling webhosts used, such as cPanel/WHM and Plesk, to support not only PHP, but the automated installation of these projects.
Sure, WordPress wasn't the first - phpNuke, Postnuke, etc, were really popular CMS tools before WP, but if we're talking staying power, you really can look at the stuff I listed as being why it has stuck around.
It's mostly that everything else was either worse (ASP), or insanely overengineered (JSP), or both (ColdFusion).
Also, with LAMP, you had a stack that was free top-to-bottom. Back then, it still wasn't as common as it is in the industry today, and that especially helped it in the hobbyist and small business niche.
When PHP gained full OOP support with PHP5 the Perl community was still tearing itself apart over introducing a MOP and which of the dozen Moose clones should reign supreme. That was the final nail in Perl's coffin, at least in it's bid to compete with PHP.
All other things being equal, security is usability[1] anti-pattern. You don't get to make clever hacks (in the original sense) on a secure system.
Unix was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. - Doug Gwyn
--
[1] at the very least for a power user or a developer
What do you mean?
There seems to be a lot of "PHP is a mess/garabage/whatever else" hyperbole in this thread with no actual explanations why.
There's inconsistencies in typing of what is returned. There's nothing wrong with loose typing, especially in the place that PHP is used. It's just that the PHP API regularly returns not what you'd expect.
Throw into the mix that the built in simple-functions are all over the place (https://www.php.net/manual/en/ref.strings.php). Seriously, there's str_replace, strpos, and parse_str. These could easily be solved by doing something similar to C#'s naming by changing it to something like String.Replace, String.IndexOf, String.Parse.
[1] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
[2] https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
"To improve the ability to execute math faster in PHP seems, at a glance, to be a very narrow scope.
However, this in fact opens the door on things such as machine learning, 3d rendering, 2d (gui) rendering, and data analysis, to name just a few."
In short, use whatever you're comfortable with. If you're super proficient with PHP, keep using it. If Python is that language for you, use Python.
In practice there is. Specifically in regard to parallelism and performance, which is important for any non-trivial application.
You can spin up multiple Python processes or just re-implement in a different language, some nuanced part of the stack that you've crafted to bottleneck(s), or you can just choose not to use it from the start. It's not like you're going to design around the deficiency at all levels.
You'll run into Ruby performance problems very early on without specific knowledge, so people just stopped using it for anything load bearing. My bias against Ruby is limited to PoC programs having memory problems and poor performance compared to virtually identical implementations in other languages, being a cultprit. YMMV.
Perl is hard for people to understand, since every feature of the language is a landmine of obfuscation...php is getting there on it's own, to be fair.
The idea that there should be no technical advantage is ignorant. There are choices that have been made and there's reasons for each. You don't run Python on stream processing with Flink because it's not suited for parallelism. Catching errors like a kafka broker disappearing, in PHP, is almost trivial like in many languages, while Java requires a custom retry method that requires intimate knowledge of how any connector works.
Knowing the languages, PHP has some very compelling strengths, as does Java (performance and safety) and Python (generally consistency of implementation and speed of development)...I still don't understand why I keep running into rats' nests of javascript and other esoterics.
I don't understand how this isn't easy on other platforms. This is such a huge advantage of PHP that somehow isn't easy to do elsewhere.
I am using pm2 to restart ts-node on file change to get around it but it does take a second or 2 or else I get hit with 502 Bad Gateway on browser reload which is sometimes annoying.
rails also does it automatically but this is not instant and sometimes shows me an old version, so I restart the rails instance manaually in case when I want to make sure which is a sad additional step that no PHP dev ever does.
Right now I just love having type definitions through TypeScript that you can never have in PHP. (Every variable and hash members starts to have a meaning, which means no mistyping of names, never specify non existing member or method and never use wrong method, as in you can't use numeric methods on string members which happens far too often in other languages and the return value is completely consistent. Say, you have a switch statement, and all of them returns a number but you forgot to add 'default' and TS complains that the method is not always returning a number.)
Ruby as a language is beautiful although it doesn't have the power of TypeScript, the code looks far more beautiful than PHP and if you like how rails works which pushes their rules down to your throat but if you feel it tasty, you might like it too.
That said, I don't think it's so profoundly amazing as to be worth learning PHP if 1) you're not already somewhat exposed to it or 2) the place where you work doesn't already use a lot of PHP.
you'll "figure it out later"? anything else that floats your boat
PHP's problems are largely user driven.
What drove you away in 2004 is likely still there.
The community is still full of people who have no idea.
Laravel is still king.
Noun driven OO is still perceived as a good idea.
But on the flip side, the language has some nice features now and performance got a big boost too.
Still a couple of things missing but it's getting there.
CSS -> Stylus. I don't even have to type brackets and colons and not just semi colons.
JS -> JS (TS). Some people may not be aware but you can fully write JS by omitting semi colons. (Except on a few occasions* but I can write a project without one just fine and decent editor will warn you when you're supposed to have one, like IntelliJ and derivatives. Configure it to not prefer semi colons and 1 shortcut key to reformat the code and all stripped.)
PHP -> Ruby, Python, JS all don't ask you for semi colons. Array expression is also too verbose in PHP.
Java -> Kotlin.
HTML -> Pug/Slim/Etc. While there's no semi colon, the verbosity of HTML is insane, people will appreciate the simplicity of template engines like Pug and never look back.
Bash -> Bash. They didn't have one decades ago...
* https://flaviocopes.com/javascript-automatic-semicolon-inser... (some random blog explaining JS semi colons)
Fuck it, go one step further and stop using languages that expect you to use any formal syntax. Just write down "Computer do this thing! Now, good and bigly like!" and then wait for it to happen.
Of all the fucking complaints about a language "requires semicolons" is the most ridiculous thing I've heard (and no you're not the first place I've heard it, but it's still as ridiculous now as it was the first time I heard it).
> Ruby, Python, JS all don't ask you for semi colons.
Except, JS does require semicolons, it just happens to be able to insert them for you in some situations.
> Array expression is also too verbose in PHP
Array syntax in PHP is the same as in JS: `['foo', 'bar', 'bar'];`. Oh that nasty semicolon is the "verbose" part I bet?
While debating myself on whether to learn rust or go next I fell into clojure. I'll probably pick go up next and then rust.
In those long lived processes, a JIT really shines!
I thought the same some days ago, but in theory, the output from JIT lives across requests so it shouldn't matter if its a long lived process or simply a normal PHPfpm process.
Also, the usual bottleneck in PHP is I/O.
For one of my PHP extensions I benchmarked the C level implementation to be 5x faster than Jitted PHP code: https://beberlei.de/2019/03/25/the_jit_in_relation_to_php_ex...
So no, if your Swoole application does a lot of async I/O and its only in CPU code to delegate between I/O, then it will not benefit from the JIT.
"Long-Running process" alone doesn't mean that its CPU bound.
The nice story here is when he was in financial trouble (because of a bad employer) the community stepped up and donated to him ( https://www.gofundme.com/b9dfcg ).
He has constantly been useful and a positive force of change and any language ecosystem would be happy to have him.
1. You may add complexity if you want but the bare metal of web is that you have some printf() like output construct plus a trivial <? ?> interpolation thing. Then who wants more can add more, but this should be what you get immediately for free, without template languages.
2. Languages, even high level ones, should be reasonably fast.
3. Setting up an environment should be trivial.
4. By default things are created and die in the context of a page load. Then if you want to optimize things, you may have additional constructs to create persistent connections, objects, whatever. But give me this huge garbage collector that is a stateless execution, by default.
5. A set of libraries already included so that for most things I don't have to go and find some solution.
Many other competitors failed so big in that regards that I really wanted PHP to get better as a language (like it is doing) so that it was not a so bad experience like at the start, because I was pretty sure the others would hardly fix the above points.
E.g. there are at least three async frameworks, with barely any adoption―and this new ‘Swole’ one is advertised like ReactPHP never existed, with its promises and everything.
Meanwhile, somehow, the poster notion of PHP's versatility is that it's purportedly just fine for desktop GUI programming, of all things―while being single-threaded (its ‘pthreads’ aren't threads). The topic of UI freezes never comes up in these pamphlets, for some reason.
But who knows? I wouldn't have thought it would be as popular as it is now, if you'd asked me 5 years ago.
> However, this in fact opens the door on things such as machine learning, 3d rendering, 2d (gui) rendering, and data analysis, to name just a few.
Shouldn't we get decent threading built in before we consider most of those? I've hit that wall many times when processing larger amounts of data w/ php scripts. I know about the pthreads plugin but nothing beats a first class citizen like goroutines for go or similar.
- https://github.com/krakjoe/parallel - https://blog.krakjoe.ninja/2019/02/parallel-php-next-chapter...
This would speed up applications more than a JIT would for most.
Though I’m very pleased that this made it to PHP 8
I do things now with Wordpress, since that grew and was maintained past AOL server. I always look forward to improvements in PHP, the last few releases have made huge strides in page load times
Even better/worse, PHP 7.2 with an opcode cache can actually outperform HHVM on many practical benchmarks [2], and 7.3 is faster still.
[1]: https://hhvm.com/blog/2018/09/12/end-of-php-support-future-o...
[2]: http://web.archive.org/web/20180305000053/https://kinsta.com...
Web PHP projects that want to add some command line programs for doing maintenance tasks etc