Optimization of php5.4 Zend Engine

Source: Internet
Author: User
Tags contains copy execution hash php code zend

On the update list for PHP 5.4, there is a sentence that improves the performance of the Zend engine and reduces memory footprint.

So, how exactly is ascension?

Avoid unnecessary hashtable.

We know that in PHP, the properties/static properties/constants of the class are stored in Hashtable, and in the past, even if a class did not declare properties/static properties/constants, the Zend engine would assign them hashtable.

And now, the process is optimized and the Hashtable is allocated only when there are elements.

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

Four-yuan optimization

In PHP, the real execution is opcodes, a opcodes contains 3 fixed operands, result, left, and right, and before that, each of these three operands contains a zval, even when it is not used at all, such as when there is no right operand, A zval is also assigned to the right-hand operand.

And now, all operands will no longer directly contain zval, but contain a pointer to a literal table, and each OP array will contain a literal table.

And Znode also made the corresponding adjustment.

This can also reduce some memory footprint. From the previous (32-bit operating system) A opcode occupies 72byte, up to now 28byte.

In addition, for string, literal table also saves a copy of this string's calculated hash value, avoiding multiple computations at run time. Thus improving the performance of a part.

Literal string

As in C, literal strings in code are stored in a fixed segment (data segment), which is a constant string throughout the execution period, cannot be modified, and cannot be free.

PHP also draws on the idea of a internal string, a literal string in PHP code that will be allocated once and cannot be modified throughout the execution period.

PHP, when copy_zval, free zval, and other operations, will be special treatment of internal string, to avoid unnecessary and copy.

And the hash value of these literal strings will be calculated in advance, so that for the string comparison = =, and for the hash calculation in Hashtable, this calculated hash value can be used directly to improve performance.

Other

Of course, there are many optimization points, such as optimizing the opcode, reducing some unnecessary opcodes, this is not to repeat.

Contrast

Here are some of the data for internal testing in the PHP development team:

Native php, no opcode Cache:

Php-trunkpatchedinprovement

bench.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) 1073.91084.81%

FW (REQ/SEC) 105.3111.86%

Hello (req/sec) 5362.55351.40%

Qdig (req/sec) 243.4253.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 these data, the performance improvement is still very 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.