Repository navigation
ext/date: Look up the time zone offset in date_format() only when used - #25738
Open
ArtUkrainskiy wants to merge 1 commit into
Open
ArtUkrainskiy wants to merge 1 commit into
ArtUkrainskiy wants to merge 1 commit into
Conversation
For every local time, date_format() allocated a timelib_time_offset and an abbreviation string before reading the format, and for a time zone identifier it also searched the transitions. Only I O P p T Z c r use them, and e for a zone given as an offset or abbreviation. The offset is now built once, when the format first reaches one of these characters, and not at all for a format without them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
date()andDateTimeInterface::format()build the time zone offset of a local time before they read the format. That allocates atimelib_time_offsetand an abbreviation string. For a time zone identifier it also searches the transitions. Most formats never use it. OnlyI O P p T Z c rdo, andefor a zone given as an offset or abbreviation.Now the offset is built once, when the format first reaches one of these characters. A format without them doesn't build it at all.
gmdate()didn't build it before and still doesn't.AMD Ryzen 9 5950X, negative = fewer cycles (faster):
format('Y'), UTCformat('Y'), Europe/Madridformat('Y-m-d H:i:s'), UTCformat('Y-m-d H:i:s'), Europe/Madridformat('Y-m-d H:i:s'), +05:30format('Y-m-d H:i:s'), ESTformat('Y-m-d\TH:i:s.u'), America/New_Yorkdate('Y-m-d'), UTCdate('Y-m-d H:i:s'), UTCformat('c'), UTCformat('c'), Europe/Madridformat('c'), +05:30format('Y-m-d\TH:i:sP'), Europe/Madridformat('D, d M Y H:i:s O'), +05:30date(DATE_ATOM), UTC~ is within the noise of master against master. layout? means the cycles changed and the instructions didn't.
On GCC that's about 500 cycles saved per call on Europe/Madrid and 150–185 on UTC, whatever the format.
json_encode()andserialize()of date objects gain too, since they format each date with'x-m-d H:i:s.u'. For 100 dates in Europe/Madrid that's 18–23% fewer cycles.Formats that use the offset, and
gmdate(), run 0–1% more instructions than on master. Their cycles move by −7% to +12%, and the slower rows change when I add-falign-functions=64 -falign-loops=32.gmdate('Y-m-d H:i:s')runs none of the new code and still moves from +8% to −2% on clang. So I read these rows as code placement, but I haven't found the exact cause.The output is byte-identical to master on over 50,000 calls. They cover every format character, escapes and random formats. The dates use time zone identifiers, offsets in minutes and seconds, and abbreviations, with years from
PHP_INT_MINtoPHP_INT_MAX. I checked that on GCC, clang, ZTS and ASan + UBSan. The ext/date tests pass on all of them. On ASan,ExtendDateTime.phptfails on master too. The new test prints the offset characters escaped and not, on every zone type and withgmdate(). I haven't measured on Intel or tested on Windows.#20758 replaces the
slprintf()calls in the same function. This PR doesn't touch them.Full numbers and scripts: https://github.com/ArtUkrainskiy/php-src-bench/tree/main/reports/date-format-lazy-offset