php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74929 mbstring functions version 7.1.1 are slow compared to 5.3 on Windows
Submitted: 2017-07-15 13:29 UTC Modified: 2018-10-22 13:15 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: andxfiles at gmail dot com Assigned: nikic (profile)
Status: Closed Package: mbstring related
PHP Version: 7.1.7 OS: Windows
Private report: No CVE-ID: None
 [2017-07-15 13:29 UTC] andxfiles at gmail dot com
Description:
------------
PHP's 7.1.1 mb_ (multibyte) functions are ~60% slower compared to PHP 5.3. Example of such functions: mb_strlen, mb_stripos, mb_substr. This affects Windows only. On Linux they seem to be way faster compared to PHP 5.3 and there is no such issue. PHP's 7.1.1 installation was done via WebPI (IIS).

Test script:
---------------
<?php
$starttime = microtime(true);
    for ($i=0; $i<100000; $i++) {
        $a = mb_strlen("fdsfdssdfoifjosdifjosdifjosdij:ά", "UTF-8");
    }
$finishtime = microtime(true);
echo "mb_strlen: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>";

$starttime = microtime(true);
    for ($i=0; $i<100000; $i++) {
        $a = mb_stripos("fdsfdssdfoifjosdifjosdifjosdij:ά", "α", 0, "UTF-8");
    }
$finishtime = microtime(true);
echo "mb_stripos: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>";


$starttime = microtime(true);
    for ($i=0; $i<100000; $i++) {
        $a = mb_substr("fdsfdssdfoifjosdifjosdifjosdij:ά", $i, 1, "UTF-8");
    }
$finishtime = microtime(true);
echo "mb_substr: " . number_format($finishtime - $starttime, 4)*1000 ." milliseconds<br/>";
?>

Expected result:
----------------
php 5.3.28
mb_strlen: 250 milliseconds
mb_stripos: 3078.1 milliseconds
mb_substr: 281.3 milliseconds

php 7.1.1
mb_strlen: 406.3 milliseconds
mb_stripos: 4796.9 milliseconds
mb_substr: 421.9 milliseconds


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-22 08:47 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2017-07-22 08:47 UTC] ab@php.net
Thanks for the report. Do you use a 64-bit build of PHP 7? If so, please compare with a 32-bit build. I basically can't reproduce such a big discrepancy, but otherwise it could be possible a 64-bit build would be slower a little bit. 

Thanks.
 [2017-07-22 10:45 UTC] andxfiles at gmail dot com
In both cases I'm using 32bit versions of php. One case is php 5.3.28 and the other is 7.1.1. The OS is Windows, the problem does not seem to exist under Linux. Both versions are installed via Web Platform Installer from within IIS.

Other people have been able to reproduce it: https://stackoverflow.com/questions/45028018/php-7-mb-multibyte-functions-are-60-slower-than-in-5-3-possibly-windows-on
 [2017-07-22 12:22 UTC] ab@php.net
Ok. As a followup - both use same flavor TS/NTS? Both tested on the same machine? Which exact Widows version?

Thanks.
 [2017-07-23 03:14 UTC] andxfiles at gmail dot com
Both versions of php are Non Thread Safe. Windows version is: Windows Server 2012 Standard 64bit. However, a user on stackoverflow (link in previous comment) has replicated it in Windows 7 as well.
 [2017-07-23 19:15 UTC] ab@php.net
@andxfiles, Nikita made quite a few improvements to ext mbstring in master, see bug #74933. I'd say, it would make sense to check some latest master snapshot, to fetch here http://windows.php.net/snapshots/ . We also work on a new PGO approach, so further improvements are to come.

Thanks.
 [2017-07-24 06:53 UTC] andxfiles at gmail dot com
ab@php.net, nikic@php.net:

Unfortunately under Windows I still see no difference. New results:

5.3.28:
mb_strlen: 309.4 milliseconds
mb_stripos: 3523.4 milliseconds
mb_substr: 326.6 milliseconds

7.1.1:
mb_strlen: 426.3 milliseconds
mb_stripos: 4812.5 milliseconds
mb_substr: 421.9 milliseconds

7.1.9-dev (master)
mb_strlen: 421.9 milliseconds
mb_stripos: 4890.6 milliseconds
mb_substr: 421.9 milliseconds
 [2017-07-24 10:30 UTC] ab@php.net
Thanks for checking. I've tested your snippet now, but the results are somewhat different.

5.3 x86
mb_strlen: 327.4 milliseconds
mb_stripos: 3125.6 milliseconds
mb_substr: 260.6 milliseconds

5.6 x86
mb_strlen: 293 milliseconds
mb_stripos: 3145.3 milliseconds
mb_substr: 342.4 milliseconds

7.1 x86
mb_strlen: 432 milliseconds
mb_stripos: 5672.8 milliseconds
mb_substr: 567.7 milliseconds

master x86
mb_strlen: 73.6 milliseconds
mb_stripos: 248.5 milliseconds
mb_substr: 69.6 milliseconds

master x64
mb_strlen: 91.6 milliseconds
mb_stripos: 312.6 milliseconds
mb_substr: 101.6 milliseconds

To see is, that indeed some slowdown made it into PHP 7. The current master however is significant faster that any previous branch, even on 64 bit. Please note, that 7.1 is not master. You need to fetch literally master snapshots from the page linked, the improvements are not anywhere else ATM.

Thanks.
 [2017-07-24 22:38 UTC] andxfiles at gmail dot com
I apologize, had not scrolled down, thought that the latest was 7.1.9.

I just downloaded and tested the master branch (7.3.0-dev) and it is indeed way faster, as your results show ab@php.net

5.3.28:
mb_strlen: 153.6 milliseconds
mb_stripos: 1814.6 milliseconds
mb_substr: 163.1 milliseconds

7.1.1
mb_strlen: 289 milliseconds
mb_stripos: 3247.3 milliseconds
mb_substr: 295.7 milliseconds

7.3 (master)
mb_strlen: 33.7 milliseconds
mb_stripos: 139.6 milliseconds
mb_substr: 41.8 milliseconds

you can mark the bug as solved. Thank you. Would be grateful if it was included on 7.2
 [2017-07-26 11:32 UTC] ab@php.net
-Assigned To: +Assigned To: nikic
 [2017-07-26 11:32 UTC] ab@php.net
Nikita, please mention this ticket, once the perf part is merged into 7.2.

Thanks.
 [2017-07-26 12:54 UTC] ab@php.net
-Status: Feedback +Status: Closed
 [2017-07-26 12:54 UTC] ab@php.net
Closing, as it is going to be first available in 7.3.

Thanks.
 [2018-10-22 13:10 UTC] andxfiles at gmail dot com
I would like to ask whether this bugfix along with https://bugs.php.net/bug.php?id=74933 will be present in 7.3 ?
 [2018-10-22 13:15 UTC] nikic@php.net
@andxfiles: Yes, both of these are part of PHP 7.3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC