[php-src] PR #25702: date: Skip timelib_strtotime call in date() for "now"
| From: | adapik | Date: | Tue, 24 Nov 2026 11:19:14 +0000 |
| Subject: | [php-src] PR #25702: date: Skip timelib_strtotime call in date() for "now" | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-40949@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25702
Author: adapik
Follow-up to b4e9b184637,
php_date_initialize() already has a shortcut for
"now": it builds the current time directly and returns. But it only takes
that shortcut after timelib_strtotime() has already parsed the string, and the parsed
result is thrown away. So new DateTime(), new DateTimeImmutable(),
date_create() and date_create_immutable(), with no argument or with
"now", spend time scanning a string and allocating a
timelib_time that nobody uses.
This change checks for "now" before parsing and skips
timelib_strtotime() in that case. Everything else is unchanged.
Benchmark
Release build, ns per call:
| Call | master | patched | Change |
|---|---:|---:|---:|
| new DateTime() | 135.7 | 92.6 | −32% |
| date_create() | 131.1 | 87.1 | −34% |