Home >Backend Development >PHP Tutorial >Github is full of joy, PHP god-level code triggers complaints
Overview: The day before yesterday, a piece of code that can improve operating efficiency by 70% suddenly appeared in the PHP section of github, triggering complaints and ridicules from many netizens around the world, "awesome!", "well done!", "PHP is the world The first language! "The programmers who are usually serious and hardworking give full play to their humorous side, and GitHub has become a sea of joy.A few days ago, a piece of code that can improve operating efficiency by 70% suddenly appeared in the PHP section of github, which triggered complaints and ridicules from many netizens around the world, "awesome!", "well done!", "PHP is the world's No. 1 One language!" Programmers who usually keep their noses in words and work hard have given full play to their humorous side, and GitHub has become a sea of joy.
Let’s take a look at this piece of divine code first:
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:
Before: Memory usage: 163.66MB (peak: 403.82MB), time: 246.25s
After: Memory usage: 163.34MB (peak: 350.36MB), time: 99.55s
The time required to run a certain PHP program was reduced from 246.25 seconds to 99.55 seconds!Before: Memory usage: 152.71MB (peak: 335.9MB), time: 195.99s
After: Memory usage: 164MB (peak: 308.02MB), time: 104.06s
The time it takes for a PHP program to run from 195.99 seconds reduced to 104.06 seconds!...In general, 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 extra 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 the program. 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 announced, the programmers on github were overjoyed:
Homm, who arrived first, expressed his surprise at this processing method and did not understand why it was done, and objectively evaluated this processing The method didn't look good:
Then smilingtechguy came and started teasing: "Well, there is no comment, let's disable the PHP kernel, and we won't explain why we do this."
Then it started to get out of hand:
Some were making fun of you:
Some were complaining and teasing:
Just talking about PHP It is the world's number one language and has versions in several countries. It is said that just using a few pieces of code can increase efficiency by 70%. PHP is definitely 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 question. A long and arduous matter.
The above has introduced the joy of Github, and the PHP god-level code has caused a lot of complaints, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.