Github happy PHP God-level code triggers SPOF, githubphp God code _ PHP Tutorial

Source: Internet
Author: User
Github happy PHP God-level code triggers SPOF, githubphp God code. Github happy many PHP God-level code triggers SPOF. the previous day before githubphp God code, the PHP section of github was surprised to see a code that can improve the running efficiency by 70%, it has triggered the sputation of Github by many netizens all over the world.

The day before yesterday, the PHP section of github was shocked by a piece of code that could improve the running efficiency by 70%, which caused a lot of comments and ridicule from netizens around the world. "awesome !" , "Well done !" "PHP is the world's No. 1 language !" At ordinary times, the cool programmers make full use of their humorous aspects. github has become a sea of joy.

Let's take a look at this piece of God-level code:

This code does one thing: disable the PHP garbage collector. Then, the user tested the effect of disabling the PHP garbage collector:

Before: Memory usage: 163.66 MB (peak: 403.82 MB), time: 246.25 s
After: Memory usage: 163.34 MB (peak: 350.36 MB), time: 99.55 s
The time required for a PHP program to run is reduced from 246.25 seconds to 99.55 seconds!

Before: Memory usage: 152.71 MB (peak: 335.9 MB), time: 195.99 s
After: Memory usage: 164 MB (peak: 308.02 MB), time: 104.06 s
The time required for a PHP program to run is reduced from 195.99 seconds to 104.06 seconds!

......

In general, disabling the garbage collector can improve the php70% running efficiency.

Since PHP garbage collection is so unreliable, what was the original intention of its previous design?

In C/C ++, memory management is a very troublesome task. the use and release of memory requires programmers to write programs for manual operations, this may cause resource waste or even memory leakage. To avoid this problem, PHP introduced a garbage collector to automatically release memory for useless objects.

It is worth mentioning that PHP will consume additional time when running the loop collection algorithm. Although this extra consumption is minimal in a small project, when running a large project, because multiple recycling threads are started at the same time, this kind of consumption will have a great impact. the most intuitive manifestation is that the running time is longer.

Disabling PHP garbage collection is the simplest and most crude way to improve the program running efficiency. This is like a leg and foot injury. The simplest way is to cut the leg.

As soon as the God-level code was published, the programmers at github were happy:

First, homm expressed his surprise about the processing method and did not understand why it was necessary to do so, and objectively evaluated the processing method as though it did not look good:

Then smileytechguy began to ridicule: "Well, there is no comment. let's disable the PHP kernel. we won't explain why ."

Then we started to get rid of it:

Soy sauce:

Sputation and ridicule:

PHP is the first language in the world, and there are several versions in the world. it can be improved by 70% with only a few pieces of code. the world's first language of PHP is well deserved:

There are also cute:

PHP's garbage collection mechanism has become a joke. we also know that simply disabling PHP garbage collection does not solve problems such as memory overflow, in the future, PHP will have a long way to deal with the conflict between memory management and operating efficiency.

Ghost PHP's God-level code triggered sputation. the previous day before githubphp's God code, the PHP section of github found a piece of code that can improve the running efficiency by 70%, triggering sputation by many netizens all over the world...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.