Home > Article > Backend Development > Github is full of joy. PHP god-level code triggers complaints, githubphp god code_PHP tutorial
The day before yesterday, a piece of code that can improve operating efficiency by 70% suddenly appeared on Github’s PHP section, triggering a nationwide stir. Many netizens around the world have complained and ridiculed, "awesome!", "well done!", "PHP is the world's first language!" Programmers who are usually serious and hardworking have given full play to their humorous side, and Github has become a joy of ocean.
First let’s take a look at this piece of god-level code:
What this code does is one thing: disable PHP’s garbage collector. Then netizens tested the effect of using the garbage collector with PHP disabled:
<p>Before: Memory usage: 163.66MB (peak: 403.82MB), time: 246.25s<br />After: Memory usage: 163.34MB (peak: 350.36MB), time: 99.55s<br />某个PHP程序运行所需时间从246.25秒降低到99.55秒!</p> <p>Before: Memory usage: 152.71MB (peak: 335.9MB), time: 195.99s<br />After: Memory usage: 164MB (peak: 308.02MB), time: 104.06s<br />某个PHP程序运行所需时间从195.99秒降低到104.06秒!</p> <p>……</p>
Generally speaking, disabling the garbage collector can improve PHP's operating efficiency by 70%.
Since PHP’s garbage collection is so unreliable, what was the original intention of its previous design?
Because in C/C++, memory management is a very troublesome thing. The use and release of memory require programmers to write programs to operate manually. If something is omitted, it may cause a waste of resources or even a memory leak. Therefore, in order to avoid this problem during PHP design, a garbage collector was introduced to automatically release the memory of useless objects.
It is worth mentioning that PHP will consume additional time when running the recycling algorithm. Although in smaller projects, this additional consumption is minimal, when running large projects, since multiple recycling threads are started at the same time, this consumption will have a great impact. The most intuitive manifestation is the program running The time got longer.
Disabling PHP’s garbage collection is the simplest and crudest way to improve the efficiency of program operation. This is just like if a leg or foot is injured, the easiest way is to amputate it.
As soon as the god-level code was released, the programmers on github were overjoyed:
Homm, who arrived first, expressed his surprise at this method of processing and did not understand why it was done, and objectively commented that this method of processing does not look good:
Then smileytechguy came and started teasing: "Well, there is no comment, let us disable the PHP kernel, and we will not explain why we do this."
Then it started to get out of control:
Those who use soy sauce:
Those who complain and ridicule:
Just saying that PHP is the number one language in the world, there are versions in several countries. It is said that only a few pieces of code can increase efficiency by 70%. PHP is well deserved to be the number one language in the world:
There are also cute ones:
PHP’s garbage collection mechanism has become everyone’s joke. We also know that simply disabling PHP garbage collection cannot solve problems such as memory overflow. How PHP handles the contradiction between memory management and operating efficiency in the future will be a task. Something serious and long-lasting.