Php5.4Zend engine optimization

Source: Internet
Author: User
In the update list of PHP5.4, there is one sentence: This improves the performance of the Zend Engine and reduces memory usage. how can this problem be solved? Avoid unnecessary Hashtable we know that in PHP, class properties/static properties/constants are all saved in Hashtabl... "> <LINKhref =" http://www.php100.com/

 

In the update list of PHP 5.4, the Zend Engine performance is improved and memory usage is reduced.

So how is it actually improved?

Avoid unnecessary Hashtable

We know that in PHP, the class attributes/static attributes/constants are stored in Hashtable. in the past, even if a class does not declare attributes/static attributes/constants, the Zend engine will also assign Hashtable to them.

At present, this process has been optimized and Hashtable will be allocated only when there are elements.

This avoids some emalloc/efree operations and reduces some memory usage.

Four-element optimization

In PHP, the actual execution is Opcodes. an Opcodes contains three fixed operands, result, left, right. in the past, each of these three operands contains a zval, even if it is not used at all, for example, if there is no right operand, a zval will be assigned to the right operand.

At present, all operands will not directly contain zval, but a literal table pointer. Each op array will contain a literal table.

Znode has also been adjusted accordingly.

In this way, some memory usage can be reduced. from the previous (32-bit operating system) one opcode occupies 72 bytes, to the current 28byte.

In addition, for string, literal table also saves a pre-calculated hash value of this string, avoiding multiple computation at run time, thus improving some performance.

Literal string

In C, the literal strings in the code are saved in a fixed segment (data segment). during the entire execution period, these strings are constant strings and cannot be modified or free.

PHP also draws on this idea to propose an Internal string concept. the literal strings in PHP code will be allocated once and cannot be modified during the entire execution period.

PHP will specially handle internal string during operations such as copy_zval and free zval to avoid unnecessary free and replication.

In addition, the hash values of these literal strings will be calculated in advance, so that for string comparison =, and hash calculation in hashtable, you can directly use this pre-calculated hash value to improve some of the performance.

Others

Of course, there are still many optimization points, such as optimizing opcode and reducing unnecessary opcodes, so we will not go into detail here.

Comparison

Below are some data tested by the PHP development team:

Native PHP with no Opcode Cache:

Php-trunkpatchedinprovement

Protocol. php (sec) 4.313.4919%

Micro_bench.php (sec) 19.7814.6326%

Some practical applications:

Php-trunkpathcedimprovement

Blog (req/sec) 59.366.212%

Drupal (req/sec) g03.94254.81 %

Fw (req/sec) 105.3111.86%

Hello (req/sec) 5362.55351.40%

Qdig (req/sec) 243.20.3.74%

Typo3 (req/sec) 355.3382.68%

Wordpress (req/sec) 101.8108.57%

Xoops (req/sec) 70.378.512%

Scrum (req/sec) 86.5104.220%

From the data, the performance improvement is still obvious ..

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.