|  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
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
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:
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-07-22 08:47 UTC]
-Status: Open +Status: Feedback
 [2017-07-22 08:47 UTC]
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. 

 [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:
 [2017-07-22 12:22 UTC]
Ok. As a followup - both use same flavor TS/NTS? Both tested on the same machine? Which exact Widows version?

 [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]
@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 . We also work on a new PGO approach, so further improvements are to come.

 [2017-07-24 06:53 UTC] andxfiles at gmail dot com,

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

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

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]
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.

 [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

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

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]
-Assigned To: +Assigned To: nikic
 [2017-07-26 11:32 UTC]
Nikita, please mention this ticket, once the perf part is merged into 7.2.

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

 [2018-10-22 13:10 UTC] andxfiles at gmail dot com
I would like to ask whether this bugfix along with will be present in 7.3 ?
 [2018-10-22 13:15 UTC]
@andxfiles: Yes, both of these are part of PHP 7.3.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue May 30 11:03:42 2023 UTC