[wp-trac] [WordPress Trac] #39163: Use REQUEST_TIME_FLOAT for timing

WordPress Trac noreply at wordpress.org
Wed Dec 7 21:09:55 UTC 2016


#39163: Use REQUEST_TIME_FLOAT for timing
----------------------------+-----------------------------
 Reporter:  andy            |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Bootstrap/Load  |    Version:  trunk
 Severity:  normal          |   Keywords:
  Focuses:  performance     |
----------------------------+-----------------------------
 `$_SERVER['REQUEST_TIME_FLOAT']`
 > The timestamp of the start of the request, with microsecond precision.
 Available since PHP 5.4.0.

 Related: #26874 timer_stop() returns a string, not a float

 WordPress should expose timing data as a float in the most accurate manner
 possible. `timer_stop()` has two problems: it uses an initial timestamp
 generated later than it needs to be (50ms late is what I have seen most
 often), and its formatted return value can not reliably be used as a
 number (some locales swap commas and periods, for example).

 As `timer_stop()` is a well-established formatting function, a new
 function is needed for getting the raw data. The new `timer_float()` will
 simply `return microtime( true ) - $_SERVER['REQUEST_TIME_FLOAT'];`. For
 compatibility with PHP < 5.4, the initial value is conditionally set at
 the top of load.php. This is all I've done in small.diff, leaving
 `timer_stop()` alone.

 My goal for this ticket is to get `timer_float()` in core so we can start
 using it for accurate and reliable timing data to support efforts to
 manage and improve performance. I don't really care whether any changes
 are made to `timer_start()` and `timer_stop()`. However, I included them
 in patches to save time just in case we want them updated.

 medium.diff changes `timer_start()` to use `REQUEST_TIME_FLOAT`. This will
 make measurements more accurate without changing any other semantics.

 large.diff bypasses `timer_start()` and automatically starts the timer as
 soon as possible, i.e. at the top of load.php. This patch tags
 `timer_start()` as deprecated but we should not move it to deprecated.php
 because drop-ins might expect `timer_start()` to exist, as might any
 auxiliary scripts that directly include load.php. (I am not familiar with
 deprecation strategy generally so I expect feedback on this.) The legacy
 globals, `$timestart` and its cousin that hopefully nobody ever used,
 `$timeend`, are both supported in this patch. (I think they should be
 deprecated as soon as we bump to 5.4.)

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39163>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list