Re: Optimizing php_html_entities()

From: Date: Tue, 23 Jun 2015 15:21:34 +0000
Subject: Re: Optimizing php_html_entities()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-86813@lists.php.net to get a copy of this message
On Tue, Jun 23, 2015 at 10:33 AM, Xinchen Hui <laruence@php.net> wrote: > Hey: > > On Tue, Jun 23, 2015 at 7:37 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: >> Hi all, >> >> I'm trying to optimize php_html_entities(). >> Since htmlspecialchars()/htmlentities() are sensitive function, I would >> like to ask comments before merge. >> >> https://github.com/php/php-src/pull/1356 >> >> Current php_html_entities() convert int/float/etc to string, then convert >> it. >> int/float/etc is not required to be escaped. Optimize it by simply >> converting them to string. >> >> Simple benchmark shows about 60% execution time reduction. >> >> [yohgaki@dev github-php-src]$ ./php-bin b.php >> Time: 10.484607934952 >> [yohgaki@dev github-php-src]$ ./php-bin b.php >> Time: 10.867615222931 >> [yohgaki@dev github-php-src]$ ./php.new b.php >> Time: 3.9379420280457 >> [yohgaki@dev github-php-src]$ ./php.new b.php >> Time: 4.0694711208344 >> [yohgaki@dev github-php-src]$ cat b.php >> <?php >> const LOOP=100000000; >> >> $start = microtime(true); >> for ($i = 0; $i < LOOP; $i++) { >> } >> $loop_time = microtime(true) - $start; >> >> $start = microtime(true); >> for ($i = 0; $i < LOOP; $i++) { >> htmlspecialchars(123456790); >> } >> echo 'Time: '.(microtime(true) - $start - $loop_time)."\n"; > But passing an non-string to htmlspecialchars are not common used cases.. > > "optimize" not common used cases... will bring nothing to us.. In addition, this breaks the contract, specifically when using scalar types. Because you're no longer going to error when the contract is broken (considering htmlspecialchars is documented as string:string). Anthony

« previous php.internals (#86813) next »