[php-src] PR #18092: Optimize PHP html_entity_decode function
| From: | ArtUkrainskiy | Date: | Sun, 16 Mar 2025 17:46:54 +0000 |
| Subject: | [php-src] PR #18092: Optimize PHP html_entity_decode function | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-31108@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/18092
Author: ArtUkrainskiy
Improvements affect the C function
traverse_for_entities:
- Use memchr to search for '&' instead of scanning character by
character.
- Use memchr to locate ';' to determine potential entity boundaries instead
of process_named_entity_html, avoiding unnecessary per-character validations.
- Use memcpy instead of character-by-character copying.
- Refactor code for improved structure and readability.
Benchmark for 4K-character strings :
```
--------------------------------------------------------------------------------------------------
| Test | html_entity_decode avg(ns) | html_entity_decode_new avg(ns) | diff(%) |
--------------------------------------------------------------------------------------------------
| 200 valid entity | 5640 | 2607 | 146.34% |
--------------------------------------------------------------------------------------------------
| 200 invalid entity | 5294 | 2094 | 152.82% |
--------------------------------------------------------------------------------------------------
| 200 & | 4016 | 1754 | 128.96%
|
--------------------------------------------------------------------------------------------------
| String endswith & | 2294 | 170 | 1249.41%
|
--------------------------------------------------------------------------------------------------
```
All tests are passed!