Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64147 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 8624 invoked from network); 4 Dec 2012 16:59:02 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Dec 2012 16:59:02 -0000 Authentication-Results: pb1.pair.com header.from=njaguar@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=njaguar@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: njaguar@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:38279] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/14-18918-5DB2EB05 for ; Tue, 04 Dec 2012 11:59:01 -0500 Received: by mail-ob0-f170.google.com with SMTP id wp18so4215684obc.29 for ; Tue, 04 Dec 2012 08:58:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=bs7nihnkEoucYNnE29eQ+RFTrHG2/ABC8Zg3BCkhSXQ=; b=hhTqJFNIlndtkGpi8cXhGpdJhiSute5mCcCHdXk9DmYuOlXJmOopG8mDCN2e2lJVxB pAF+nf/54fLJdNlf+LnWk/dceUDII1tHZWOAsQZChOCX2wcw0mQaE0DjqGxS21k/1DeE 1FgAU7TZBImGKeyap9HauNYrs2/sLwezNZNnXR3crgNoEgy44Moxsz/G0kryPQYvbhAN gAuciy6MLDSgFJdoNOPKSKcnUSTFF4adfRvxt6oR2W1quW6zvRvo2WunWVSyGh0TSBuk pWPZL56ATknoV2267XzvNGJJxTFpiIVZg7OmRzR0usKWCaBpcrIKDXJDz8HtU7tKeq/m f0OQ== MIME-Version: 1.0 Received: by 10.60.29.70 with SMTP id i6mr12462743oeh.38.1354640338919; Tue, 04 Dec 2012 08:58:58 -0800 (PST) Received: by 10.182.89.66 with HTTP; Tue, 4 Dec 2012 08:58:58 -0800 (PST) Date: Tue, 4 Dec 2012 10:58:58 -0600 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: date/strtotime poor performance - further digging (v 5.4.9) From: njaguar@gmail.com (Paul Taulborg) So, I've been going through the internals of date() and related, trying to isolate where some poor performance is, to try and find ways to optimize it. In doing so, I came across this: On line 863 of ext/date/php_date.c is this code: } else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) { I noticed it's checking every time that the timezone is "still" valid. Commenting this out results in a tremendous speed increase. From my tests before, I saw 3.3 seconds for strtotime, and 1.75s for date. After commenting out the timelib_timezone_id_is_valid check above, speed increased to 2.3s and 1.2s respectively! (Tests are run 1 million times each) It immediately jumped out at me, because on a few lines prior is initializes DATEG(default_timezone) and checks to make sure it's valid there. Additionally, in PHP_FUNCTION(date_default_timezone_set) it also checks to ensure it is a valid timezone. Having only glanced at what ini_set() does internally, I can presume this check is there to prevent a bad value being set via that command? However, I'm not certain it directly writes the value to DATEG(default_timezone), so it may not be relevant at all. If it does, some better cursory bounds checking in ini_set() might save a lot of redundant bounds checking during runtime calls. It would also make more sense to error them out on the ini_set() line rather than on a date() call that was the result of an improperly configured value. Rather than spending time digging into that when it may not be applicable I figured I'd ask here if anyone is more familiar with the inner-workings of ini_set and other globals that can give me some insight into this? Seems like an easy optimization to make, if I'm not missing something else. Thanks!