php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66295 fetch_timezone_offset has poor performance
Submitted: 2013-12-15 01:37 UTC Modified: 2021-04-07 15:59 UTC
From: ben dot maurer at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
18 - 8 = ?
Subscribe to this entry?

 
 [2013-12-15 01:37 UTC] ben dot maurer at gmail dot com
Description:
------------
fetch_timezone_offset does a linear search through the list of time transitions. Many timezones have a rather large number of transitions. Eg, Pacific time appears to have ~180 transitions.

One possible solution might be to do a binary search rather than a linear search of the list of times. But a simpler solution could be to do a search backwards in the array: most people probably do manipulation of recent rather than old dates

I tested this using HHVM, which uses the same upstream timezone code as PHP.

Test script:
---------------
<?
date_default_timezone_set("America/Los_Angeles");
for ($i = 0; $i < 10000000; $i ++) date('I');

Expected result:
----------------
figuring out the DST rules should not be a perf issue

Actual result:
--------------
perf record shows timelib_get_time_zone_info taking a substantial amount of time

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-29 17:11 UTC] cmb@php.net
-Package: timezonedb +Package: Date/time related
 [2021-04-07 15:59 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-04-07 15:59 UTC] cmb@php.net
This is impemented[1] as of timelib 2021.3, so should be in PHP
8.1.

[1] <https://github.com/derickr/timelib/commit/550d068274be0dea9badd94b1be6be113f84eeef>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 07:01:29 2024 UTC