I understood that I was talking about running speed. So the answer is that should not consider performance for micro-optimizations.
Understand that languages do not have speed. At most they have a philosophy that makes it easy or not to have speed. Implementations already have a little more. But not so much. Often the performance is in the library used.
It is possible for something punctual in PHP to be faster than Java. Why? Java has few, but some costs that a lower level language, like C, has. If a PHP function can be written in C, and many of the standard library are, and you don’t have to access much of the PHP virtual execution machine, it’s possible that this function can be faster, as long as the function is very well written. I’m talking about thesis, in practice I don’t see it happening much.
PHP can run faster and with HHVM can improve. Today less, because the PHP implementation has improved a lot. It has several tools that help. But it has other issues that cannot be solved without the language turning into something else. In PHP 8 it will improve more.
Here’s a cruel truth that many PHP amateurs (yes, they love the language) hate to hear: people involved with language development are not the best engineers in the world, do not have a very adequate theoretical basis of languages, and took a complicated legacy, aside from not having the resources necessary to create an extremely fast language.
Note that the benchmarks that show improvements in PHP disregards the load that has worsened a lot by doing a pre-compilation and optimization. When comparing the whole, where PHP is used the whole is much more important than in other types of application, the gain is not so great. Never forget that people who like or produce a technology will use measurements that best meet your needs for marketing, which is legitimate, just do not lose sight of that.
I believe that when they say that PHP does not focus on its performance, it would be compared to other languages/technologies?
Yes, it always has to be compared to other languages. But nobody said that PHP is the slowest language there is. And it improved. PHP is faster than Ruby (standard and current implementation), faster at some things than Python, wins at some Moon points (although Luajit no longer occurs), and loses ugly to Javascript (Nodejs to compare with backend). It doesn’t come close at all when the comparison is with C/C++, C#, Java, D, Rust, Delphi, Go, VB.NET, F#, etc.
This would be about PHP being an interpreted language?
One of the main reasons. But also for having dynamic typing (probably the biggest reason in longer executions), so everything has to be checked internally before executing. Some optimizations are not possible because of this, and for being interpreted as well.
Also by having mechanisms fit all. Essentially it has no diverse data structures, it has the array assoaciative and serves for everything. It even has different structures, but are terribly implemented.
It has a number of misguided decisions that make language not perform that could.
Think that you have a load, a preparation of the environment and the compilation of the text to then execute.
Only PHP or all languages interpreted or correlated?
All following the same philosophy. It is not possible to beat the performance of a code generated by a good compiler and that "everything" is solved at compile time.
It is possible to make interpreted languages have a very interesting final execution and in some cases even beat compiled languages. But it is extremely difficult, costly and the better the execution result the worse the load time will be. Running script this tends not to compensate much.
Hack is PHP compiled and static typing, is much faster. But could more if you didn’t want to maintain good compatibility with PHP.
This is said because PHP is not meant to be fast. Simple as that. PHP was created to be easy and fast to deliver, giving up performance, which in web applications is not critical. If you need performance don’t use PHP, just like if you need to hammer a nail, don’t use pliers.
I agree with the general idea, but performance for web is just not critical for very simple things. What makes sense to use PHP. But it makes no sense to OOP with PHP.
When it’s something with a lot of access, it has a lot to do, performance is critical because it costs more to maintain infrastructure that can handle something slower. Worse still, it may need extremely more complex solutions to distribute the work, and this is very expensive. People don’t even realize they’re paying more than they should. Or that they don’t need the technology they’re using.
I’m not even talking about the opportunity cost of losing a user because it took a long time to respond.
Forget performance in PHP
Obviously this goes for micro-optimization. PHP benefits from macro gains. Choosing how to do can give interesting gains.
Why not focus on PHP performance
Because the gain will be small and the cost will be enormous. Language does not help to gain performance and has cost that has nothing to do that will still be the bulk of the running time. In some languages it is possible to win in 80, 90% of the code path. In PHP it usually gives a maximum of 50, 60%, often less.
Also the fact that most websites have little access and do not need this gain. Just for having little access does not pay to spend a lot on it. Giving performance costs more expensive.
a project that makes access to a database will have the access time to the database much longer than the execution time of the PHP code
This is not always true, especially in PHP codes because it is common for the programmer of this language not understand all the costs. If he does something complex in PHP that could be done in the database, and I see this happening too much, in PHP it will cost more than in C# or Java.
Now, an important issue is that PHP almost invariably accesses database. There are other languages that do not. When there is no IO the performance gain is more important. In fact IO generates a cost that makes performance gains less relevant.
For the answer to be complete I need to quote the Isac comment:
Most of the questions of "How can I improve the performance of this?" focus on micro optimizations almost always irrelevant to the scenario in question. Things like "use an extra variable or not in this case or not?
Man, I see a lot of gnt talking bad about
PHP
, usePHP
for years and never had problems with performance, certainly there are technologies that have better performance, after all that is the purpose of technological evolution, evolve, at least in my viewPHP
has life ahead of him yet.– Wees Smith
@Weessmith It’s not bad talking, it’s about php’s performance being irrelevant about other technologies (I believe, the compiled ones). But of course you’ll always have the "your need" factor, so what’s best for you, regardless of technology.
– rbz
Who signaled as "mainly based on opinions", the idea is not opinion. It’s about knowing if there really is a difference in performance over PHP technology over another. Mainly by the same speech it would be: "The best technology is the one that serves you". I just wanted to know why they say that, and not opinions. Or please tell me why you consider it an opinion ! :)
– rbz
Set performance: Run faster even on older machines or is it easier to evolve and maintain or easier to produce? How the quality of the workflow and code produced impact on this perhaps more than the technology used
– jean
Your question is too broad to get a satisfactory and objective answer. Performance is the magic word that people use as the final determinant for any discussion about technology, but there are other aspects to consider and each situation is different. Ask a question that focuses on something specific and can be compared without putting language as a whole on trial.
– Pagotti
@Jean I gave a better example in the question.
– rbz
@Pagotti the question would be yes very broad, but I focused more on "Why do you say that", "Why not focus on performance in PHP", and from what I understand, is that because it is an interpreted language not as many alternatives as another compiled, but not that the language is bad, for no language is.
– rbz
Just to throw a little more wood on the fire, most of the questions of "How can I improve the performance of that?" focus on micro optimizations almost always irrelevant to the scenario in question. Things like "use an extra variable or not in this case or not ?"
– Isac
@Isac So Isac, but these statements of "Disregard focus on PHP performance" are only in PHP or in all interpreted languages ? It’s because it’s interpreted that it doesn’t have as much emphasis on focusing on performance ?
– rbz
I suggest you change this title, ta bem clickbait.
– user28595
This is said because PHP is not meant to be fast. Simple as that. PHP was created to be easy and fast to deliver, giving up performance, which in web applications is not critical. If you need performance don’t use PHP, just like if you need to hammer a nail, don’t use pliers.
– Woss
@Articuno I didn’t even know what "clickbait" was until now ! rs... I liked the title of Woss, but I think it ran away. See
– rbz
@Andersoncarloswoss is exactly what I wanted to know!! But I just had to say, if this is more with PHP or all interpreted languages, or web in general ?
– rbz
@RBZ is hard to use the word all, but, in general, yes, interpreted languages have lower performance. The same happens with Python, for example.
– Woss
@Simple andersoncarloswoss. It was that guy. If you can answer, for me it is answered. It is very difficult to ask such a question, it is difficult to specify the purpose of the question, leaving it easy to interpret. I expected downvote, too wide, duplicated. Thank you very much.
– rbz
Particularly, I liked the question. I’ve had this question before, but I didn’t ask for lack of courage. kkk Thanks RBZ!
– Andrei Coelho
@Andreicoelho I’m here sweating hoping not to close ! rs
– rbz
If you close I will vote to reopen, your question is technical and not opinionated, the question is not how to make any code fast written in PHP (what this would be opinionated), but rather understand why PHP is not considered fast. (ps: I intend to give a slightly different answer from the others, as soon as I have some time to create an explanation as technical as possible, it will probably be more complementary).
– Guilherme Nascimento
@Guilhermenascimento Exactly ! It’s practically: "Why is the performance in PHP not as considered as in other ? Because it is interpreted ?". And the "comparison" with other languages, would be in this focus ! I will definitely be waiting for your answer !
– rbz
Anxiously awaiting the reply of @Guilhermenascimento... =) Usually very good!
– Andrei Coelho