[wp-trac] [WordPress Trac] #25073: Heartbeat performance and API improvements
WordPress Trac
noreply at wordpress.org
Sun Aug 18 19:55:43 UTC 2013
#25073: Heartbeat performance and API improvements
-------------------------+-----------------------------
Reporter: evansolomon | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords: has-patch
-------------------------+-----------------------------
There are a few separate changes here:
* Make some easy performance improvements
* Add a new API method
* Cleanup some style
**Performance**
Three changes here. Linked JSPerf results are from Chrome Canary (v 31).
1. Cache `$(document)`. It gets used a bunch of times. [http://jsperf.com
/jquery-doc-cache 15x faster]
2. Get rid of a few unnecessary closures in callbacks. Stuff like
`asyncMethod( function() { callback() } )` is simplified to `asyncMethod(
callback )`. [http://jsperf.com/extra-closures 4x faster]
3. Use `Date.now()` instead of `(new Date).getTime()` and remove the
unnecessary `time()` function (its optional argument was never used).
[http://jsperf.com/date-now-vs-gettime 2x faster]
**API**
I made `connect()` a method on the `Heartbeat` instance. I've wanted to
trigger a connect event a few times without waiting for the next scheduled
tick to fire, which I think is a reasonable use case. Your mileage may
vary.
**Style**
* Explicitly use `window` when referencing globals (`ajaxurl`, `pagenow`,
`wp`).
* Remove a stray leading space.
* Remove an unreachable `break`.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25073>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list