Bug #81378 [Opn]: mb_detect_encoding() performance regression in PHP 8.1

From: Date: Tue, 24 Aug 2021 19:30:53 +0000
Subject: Bug #81378 [Opn]: mb_detect_encoding() performance regression in PHP 8.1
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236054@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81378&edit=1 ID: 81378 Updated by: nikic@php.net Reported by: gfpuba+php at gmail dot com Summary: mb_detect_encoding() performance regression in PHP 8.1 Status: Open Type: Bug Package: Scripting Engine problem Operating System: Win10 Apache/2.4.48 PHP Version: 8.1.0beta3 -Assigned To: +Assigned To: alexdowad Block user comment: N Private report: N New Comment: I've applied a couple of obvious optimizations in: * https://github.com/php/php-src/commit/3be94217f4c353e718db6d823dbd74a29522fce3 * https://github.com/php/php-src/commit/f458b16041b6c9101d2f846027aba4a4b08e5a50 * https://github.com/php/php-src/commit/425c2e3ba1e3096f26adfef70f8afac9ae835ba9 There's more that can be done here, though I'm not sure how final the "algorithm" here is. Maybe Alex wants to take a look as well... Previous Comments: ------------------------------------------------------------------------ [2021-08-24 13:35:32] nikic@php.net Encoding detection now scores encodings based on character properties, and the property lookups are very expensive and make up the majority of the execution time now. We don't actually need them for the case of a single encoding, but I assume that was just a minimal reduction, because calling mb_detect_encoding() with a single encoding doesn't make sense (mb_check_encoding() should be used instead). ------------------------------------------------------------------------ [2021-08-23 20:10:41] gfpuba+php at gmail dot com Description: ------------ The following code takes 10 times longer to execute on PHP/8.1.0beta3 compare to PHP 8.0.8 Test script: --------------- $a = str_repeat('abcdef', 10000); $b = mb_detect_encoding($a, 'UTF-8', true); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81378&edit=1

« previous php.bugs (#236054) next »