Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:86813 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48565 invoked from network); 23 Jun 2015 15:21:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jun 2015 15:21:39 -0000 Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.179 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.217.179 mail-lb0-f179.google.com Received: from [209.85.217.179] ([209.85.217.179:33015] helo=mail-lb0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 52/55-18293-18979855 for ; Tue, 23 Jun 2015 11:21:38 -0400 Received: by lbbvz5 with SMTP id vz5so8967278lbb.0 for ; Tue, 23 Jun 2015 08:21:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Pox/nt5Yc+EgX+aLNizFtmaOAd+WVxQtPzN8Fb26y7I=; b=0BihEQzFTx3uXVxcxvAKfOI28Ku5pu5m23pRjf+NZJP8eRKm7IX3SSqBp6Zfal98ko 4ahWgFibkWLXMxEXE38lTsE8IYaGwElYiTIQUxUPLJt7NV953v++0wdRI7+/JxbA138+ lJUSOKpCVpjqZOUN4Kp+w8SE2wmij+Bo1t1ADY67MeOJkWir9mfC2uhrBpIsEzCleKIG gvHqKCdFsqVEizM6oiNofDhOo5ilO4734osJNmFwdcyEBEq2OtD+6EEMYLL2LjoF8FDr TBqAtmyWF9Nb5QMbBMHhjFi1mVdQ3JPwjopvlvKe6sn4aodj3L1KWjcT01NJyPP7e395 AfbQ== MIME-Version: 1.0 X-Received: by 10.112.124.71 with SMTP id mg7mr35656101lbb.38.1435072894904; Tue, 23 Jun 2015 08:21:34 -0700 (PDT) Received: by 10.25.90.75 with HTTP; Tue, 23 Jun 2015 08:21:34 -0700 (PDT) In-Reply-To: References: Date: Tue, 23 Jun 2015 11:21:34 -0400 Message-ID: To: Xinchen Hui Cc: Yasuo Ohgaki , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Optimizing php_html_entities() From: ircmaxell@gmail.com (Anthony Ferrara) On Tue, Jun 23, 2015 at 10:33 AM, Xinchen Hui wrote: > Hey: > > On Tue, Jun 23, 2015 at 7:37 PM, Yasuo Ohgaki 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 >> > 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