Skip to content

PHP8.1 Slow processing speed of string operations #12684

Closed
@toshimitsu-sato

Description

@toshimitsu-sato

Description

Does not occur in PHP8.0

The following code is slow when updated to PHP8.1
The functions used are below

  • strlen
  • mb_convert_encoding
  • str_replace

The following code:

3500 data are set in $data
In PHP8.0 it takes 2 seconds to complete. It takes 3 minutes with PHP8.1

<?php
                foreach ($data as $record) {

                    $csvData = array();

                    foreach (array_values((array)$record) as $item) {

                        if (strlen($item) !== strlen(mb_convert_encoding(mb_convert_encoding($item, 'SJIS-win', 'UTF-8'), 'UTF-8', 'SJIS-win'))) {

                            $notExistsUnicodeValues[] = $item;

                        } else {

                              $csvData[] = str_replace(array("\r\n", "\r", "\n"), "\n", $item);

                        }

                    }
                }

PHP Version

PHP 8.1.0

Operating System

・Ubuntu 20.04
・CentOS Linux release 7.9.2009

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions