Web Performance: When millisecond resolution just isn’t enough


Sometimes measuring time in millisecond resolution just isn’t accurate enough. Together with industry and community leaders, the W3C Web Performance working group has worked to solve this problem by standardizing the High Resolution Time specification. As of this week, this specification has been published as a Proposed Recommendation (PR) and is widely adopted in modern browsers. Take a look at the What Time is it? test drive demo to see how this API works.

This specification has gone from just an idea to PR in eight short months. The PR stage of standardization is the final step before a Web standard becomes an official W3C Recommendation. Additionally, this interface has been broadly adopted in browsers, including full support in Internet Explorer 10 and Firefox 15, and supported with a prefix in Chrome 22. This is a great example of what’s possible when the industry and community come together through the W3C.

So why aren’t milliseconds good enough? Time has long been measured in the Web platform using some form of the JavaScript Date object, whether it is through the Date.now() method or the DOMTimeStamp type. The Date object represents a time value as time in milliseconds since 01 January, 1970 UTC. For most practical purposes, this definition of time has been sufficient to represent any instant to within 285,616 years from 01 January, 1970 UTC.

For example, at the time of writing this blog, my Date.now() time value from my IE10 Developer Tools Console was 1350509874902. This thirteen digit number represents the number of milliseconds from the origin of this time base, 01 January, 1970. That time corresponds to 17 Oct 2012 21:37:54 UTC.

Though this definition will continue to be genuinely useful for determining the current calendar time, there are some cases where this definition is not sufficient. For example, it is useful for developers to determine if their animation is running smoothly at 60 frames per second (one frame painted every 16.667 milliseconds). Using the simple method of calculating the instantaneous FPS by measuring when the frame drawing callback was last made, one can only determine FPS to 58.8 FPS (1/17) or 62.5 FPS (1/16).

Similarly, sub-millisecond resolution is also desirable when accurately measuring elapsed time (e.g., using the Navigation Timing, Resource Timing and User Timing APIs to instrument your network and script timing) or when attempting to synchronize animation scenes or audio with animation.

To solve this issue, the High Resolution Time specification defines a new time base with at least microsecond resolution (one thousandth of a millisecond). To reduce the number of bits used to represent this number and to increase readability, instead of measuring time from 01 January, 1970 UTC, this new time base measures time from the beginning of navigation of the document, performance.timing.navigationStart.

The specification defines performance.now() as the analogous method to Date.now() for determining the current time in high resolution. The DOMHighResTimeStamp is the analogous type to DOMTimeStamp that defines the high resolution time value.

For example, looking at the current time using performance.now() and Date.now() in the IE10 Developer Tools Console at the time of writing this blog, I see the following two values:

performance.now():           196.304879519774
Date.now():        1350509874902

Even though both of these time values represent the same instance in time, they are being measured from a different origin. The performance.now() time value definitely feels more readable.

As High Resolution Time is measured from the start of a document’s navigation, performance.now() in a sub-document will be measured from the start of navigation of the sub-document, not the root document. For example, suppose a document has same-origin iframe A and cross-origin iframe B, where a navigation occurred in iframe A about 5 milliseconds after the start of navigation of the root document and in iframe B about 10 milliseconds after the start of navigation of the root document. If we measure the exact moment of time 15 milliseconds after the start of navigation of the root document, we would get the following values for performance.now() calls in the different contexts:

performance.now() in iframe B:                                5.123 ms

performance.now() in iframe A:                               10.123 ms

performance.now() in root document:                    15.123 ms

Date.now() in any context:                         134639846051 ms

Figure illustrating the difference of how Date.now() measurement compares with performance.now()

Figure: Date.now() is time measured since 01 January 1970, whereas performance.now() is time measured since the start of the document navigation

This design not only ensures there is no data leakage on the time of creation of the parent in cross-origin iframes, it also allows you to measure time relative to your start. For example, if you were using the Resource Timing interface (which uses High Resolution Time) to determine how long it takes for a server to respond to a resource request in a sub-document, you wouldn’t need to make adjustments to take the time of adding the sub-document to the root document into account.

If you wish to do cross frame time comparisons, you would just need to request top.performance.now() to get a time value relative to the root document’s start of navigation, which would return the same value in all same-origin iframes.

Another significant benefit of this API over Date.now() is that performance.now() is monotonically increasing and not subject to clock skew or adjustment. The difference between subsequent calls to performance.now() will never be negative. Date.now() doesn’t have such a guarantee and in practice we have heard of reported cases where negatives time have been seen in analytics data.

High Resolution Time is another great example of how quickly new ideas can become interoperable standards that developers can depend on in modern HTML5-enabled browsers. Thanks to everyone in the W3C Web Performance Working Group for helping design this API and to other browser vendors for rapidly implementing it with an eye towards interoperability.

Thanks,
Jatinder Mann
Internet Explorer Program Manager

Comments (31)

  1. Richard Simpson says:

    Very cool!

  2. Jane says:

    That's awesome!

    Now how about this Flash List mess? Can you please answer some questions for once in a 4 month period?

    What about all the usability issues with Metro IE on the desktop and Windows 8 in general?

    What's with the delayed Windows 7 release of IE10? Care to at least apologize for failing to meet your promised deadline? or at least explain how on earth you plan to get the bug fixes from the Win7IE10 preview release into the already shipping Win8IE10 RTM release?

    Or are you going to keep ignoring the press, the users, the reviewers, the developers, and everyone else that have told you point blank there are major issues with your new OS and we are not happy at all!

  3. @Jane says:

    I think they are mostly looking for bugs specific to Windows 7.  But I imagine if they do find major bugs, then the fixes would be combined with the security updates that come out every once in a while.

  4. Sean says:

    So since you're ignoring us in the last post we need to post our questions in this post!

    If we understand correctly you're telling us that for IE10 we need to test in three completely different browsers that behave differently and have a different code base!!???!

    Windows7 version, Windows 8 metro version and windows 8 desktop version!

    They behave different, bugs in one don't occur in the other, one we haven't even seen yet, and of the two we have seen the usability is the worst we've seen.

    There's a reason why you need to have a public beta on windows 7 and shipping it IMHO 7 months late is rediculoius!

    There's no way I'm supporting this mess… I'll support the desktop versions only… If even that.

  5. @Sean says:

    Good job completely exaggerating the situation.  Testing in one version of IE10 should be fine for 99.99% of websites.

  6. Mike says:

    why don't you just show us the real results ???  IE10 has the worst support for html5 standards. See the results : caniuse.com   . As google says "it's all about results!!!"  About the performance just wait 1 month after release and I'm sure that all the other browsers will overtake IE10 in every possible test.

     And let's not forget that   IE10 will get updated/upgraded only after 2 years so it still keeps the crown of the worst thing happened  to the internet

  7. Samantha says:

    I'd like to get a status update from Microsoft regarding the highly controversial Flash Whitelist in IE10 in the Windows 8 Metro mode.

    There's been all kinds of comments about it from the issues to submit sites to the issues for users that don't understand why their content doesn't work anymore and claims that there are new security problems due to the double browser confusion.

    How many submissions to the whitelist have been rejected so far?

    How many have been accepted (and I'm seriously curious how they managed to pass the tests when there is no hardware available for them to test on)?

    What is Microsoft planning to do to address the plugins usability issue in Metro? Right now a user accesse a site that needs a plugin and the site detects that it can't run this presents an install button for the plugin (eg Adobe Flash install button) users try to click the button but they get taken back to their desktop for the install which then determines flash is already installed. Users think the install was a success but returning to the site it still won't load and the install button is still there.

    As a usability expert I find it hard to believe that Windows 8/Metro IE ever even got sign off from management to be released.  If these were products that my company had made we would be back at the drawing board deciding how to fix them before even considering releasing them to the public.

    My fingers are crossed that there is a major patch in the works that is a mandatory install timed for release by the 26th.

    Speaking of usability this comment form is broken. I had to retry 3 times to submit! Luckily the browser I use saves my form data unlike IE.

  8. George says:

    I'd rather not hear about Flash-related topics anymore… It's annoying and flash needs to die a.s.a.p.

    As for Immersive IE, the less sites with Flash, the better. Flash is a resource hog (memory, processor, power) and it causes crashes to every browser.

  9. jens says:

    @George

    ajax is not better. Its consume mem, cpu time and have a lot of mem leaks. On client side and on Server site.

    Ajax Crasj often the browser and generates browser hooks.

    No Response of Browser. Flash is more responsable than HTML bullshit

  10. @jens says:

    Thats not even remotely true.  Lets look at this: mem/cpu time, uh flash is less efficient in that regard.  Mem leaks, can't really comment on this but thats really the browsers/developers problem and not a problem with ajax itself.  Server side?  It has no effect at all on your server side code.  Crashes?  Flash crashes more often than ajax.  Any crashes with ajax would probably be a flaw in your browsers javascript engine.   Flash more responsible than HTML?  Uh, that comment is so silly that it doesn't even really justify an answer.

  11. @George says:

    All I have to say is that Flash is an excellent piece of software, the fault is in the developers. Developers can make a horrible experience and crash software. Now imagine this…Flash goes away, where do all those bad developers start making their crappy games in? You're correct, HTML. Now you'll have crappy resource hogging HTML games, congratulations. Bad developers make crappy software regardless of the platform.

  12. stop calling it immersive IE says:

    For the love of all thing sane please stop calling it immersive IE! you sound like an utter fool calling it that. There's nothing immersive about it and we don't want any msft trolls like George on this site spreading FUD.

    Its Metro IE or Metro Mode IE until the lawyers tell us otherwise.

    Now back on topic – what's the story about Flash Blocking by default? Is Microsoft going to start talking about this?  The Web is going nuts right now talking about how messed up Windows 8 is and how Microsoft is "Big-Brothering" the Internet with this Flash list and yet you don't take 10 minutes to compose a single reply.

    how un-big brotherly of you.

  13. @stop calling it immersive IE says:

    Flash is not blocked by default. The website which qualify as respecting web-standards, touch, multi-touch and low-power devices would be while listed and can be viewable in Metro IE. In desktop-IE (for high-energy and powerful devices) would not implement the white-list and you can access any flash movie in it.

  14. Dean says:

    Hi Jatinda,

    would it be possible for the new javascript engine to expose some metrics as public properties so us devs can get meaningful stats? whats the bet DART will not dso this…

    thanks

    Dean

  15. aamwaj says:

    http://www.aamwaj.com/…/t39090.html صور بنات للتصميم

    http://www.aamwaj.com/…/t43342.html صور متحركه مسلسل ايام الزهور

    http://www.aamwaj.com/…/t42523.html صور ميسي

    http://www.aamwaj.com/…/t42522.html صور كريستيانو رونالدو

    http://www.aamwaj.com/…/t43321.html صور جواد

  16. Emil says:

    Excuse me?!

    Flash in Metro IE (which runs on the PC/Laptop people!!!) and is the default browser will indeed block all flash by default! (Even Microsoft is not denying this!)

    In order to get your content white listed (the stuff you publish, not the stuff you as an actual user would like to see!!!) you must submit it to Microsoft for consideration.

    Submitting for consideration REQUIRES YOU to test on multi touch Windows hardware that YOU CAN'T BUY YET!!!!

    This is the problem that has developers pi$$ed off!!!

    Microsoft, please start responding to comments on this blog!  Your silence is killing us and making developers despise Microsoft!

  17. flashisdead says:

    Flash has been dying from the moment that Apple decided not to support IT in iOS.

    Get a new job!!!

  18. Spencer says:

    @flashisdead yeah I keep hearing that but for the last 4 years on my iPhone and iPad every time I access a site with a video clip or an audio stream or a complex interactive security measure I can't see/use the content because Steve Jobs had a temper tantrum like a 7yr old with Adobe (and technically google, and Samsung and Microsoft, etc.)

    If Microsoft wants to kill it in their tablet we have no issue… But killing it on our laptops is a bit severe!

    What's wreaks of meddling is that flash is available but only to those on the list.  We applied but because we couldn't test on the hardware required (cause you can't buy the stuff!) we got denied!

    We're begging you Microsoft please stop playing this charades game and start responding to our questions!

    What makes you think that a flash whitelist is a good idea? Especially when absolutely no one agrees with you as a user defined blacklist makes more sense.

  19. @windows&IE team says:

    Microsoft has no plans for a second Windows 7 Service Pack

    http://www.theregister.co.uk/…/print.html

    —————————————————————–

    Is this a true talk?

    If temporarily true, it is visible only to the intrigue of your company of wanting to make Windows 8 bought compulsorily.

  20. Jim says:

    Will the bugs in the Metro IE browser in Windows 8 also be present in IE for Windows Phone 8?

    Eg will window.prompt(); and similar JavaScript that fails in Metro IE on Windows 8 also continue to fail on Windows Phone 8?

    Can we presume the it will be a port if the Windows 8 code or is it a re-write like the Windows 7 version of IE10?

  21. Naos says:

    Great to hear that Microsoft is participating in creating web standards and that at last it is following and implementing the standards! Thumbs up! It's a pleasure to see how IE10 runs complex sites or animations smoothly.

    What worries me though is that today I got email saying: Hey a new update to your Xbox ! You can use IE on Xbox now, you just need to pay each month for Gold account to use it! What ??? My console is continuing to be more and more usless without paying monthly fee, I'm just gonna sell it.

  22. @Naos says:

    How does adding a browser make your console less useful?  You never had the browser before, you still don't have it.  Nothing changed.

  23. Xavier says:

    Is there a GroupPolicy in Windows 8 to disable Metro IE or at least force desktop IE to be the default IE?

    We run IT for about 1,000 employees and when we upgrade (after the first service pack of course!) we want to make sure users don't get stuck in Metro IE and have to call IT to get out of it or make desktop IE the default.

    If there is a way to disable it completely that would obviously be best but at least forcing desktop IE to be the default IE will save us countless hours of IT support calls.

    Thanks,

    Xavier

  24. Naos says:

    It makes because nowadays when something stays in place then it actually moves backwards. When other platforms offer more and more features without paying monthly fee then Xbox is less and less useful without Gold account.

  25. @@windows&IE team says:

    Win 8 is not compulsary to buy. Aren't you recieving updates on Win7? yeah me too. Service pack combines all the past few months updates to one setup. Microsoft will keep pushing updates for Win7 till by January 14, 2020 (windows.microsoft.com/…/lifecycle). So stop spreadin this fud bullshit.

  26. Blair says:

    Quote: "During Microsoft’s official launch event for Windows 8 in New York City today, Steven Sinofsky, the president of the company’s Windows and Windows Live division, said that the company’s new operating system went through 1,240,000,000 hours of testing in public in 190 countries. “No product anywhere receives this kind of testing anywhere in the world,” he said."

    Wow! that is impressive! Too bad Microsoft didn't listen to **ANY** of the feedback about the terrible usability or enable developers to test out the new version of the browser on their existing Operating System (Windows 7).

    If you had enabled that you would have found bugs quicker, got more feedback, and had enough time to fix some of the really glaring issues that still plague the RTM release of IE10/Windows 8.

    However once again this just goes to prove that Microsoft simply doesn't care what developers and users think of their products.

    Way to Fail!

  27. Tom says:

    @Blair, your feedback is not neccessary any way. Time to get back to your Ghole. Goodbye!

  28. Jacob says:

    Well this review of Windows 8 pretty much sums the whole thing up.

    "Windows 8: The disastrous result of Microsoft’s gutless equivocation"

    http://www.extremetech.com/…/138701-windows-8-the-disastrous-result-of-microsofts-gutless-equivocation

    Choice quotes from the article:

    "As consumers who actually have to interact with this crazy, cross-paradigm hodgepodge of an interface, the utter ludicrousness of this decision is plain to see. For developers and specialists, though, the problem is far worse. For these experts, who are the actual lifeblood of the Windows ecosystem, Windows 8 comes across as confused. If you’re baffled by Windows 8, then I assure you that developers, sysadmins, and other businessy types are looking at Windows 8 with the same agape, aghast scrutiny that one gives a circus freak."

    Yeah that's exactly how I feel it is an Operating System that simply can't make up its mind what direction it is going in… even per device it can't figure it out so it went for the mediocre mix down the middle.  Not quite the tablet interface you need on a tablet and a letdown experience on the desktop.

    "With the release of Windows 8, no one in the software industry really knows what to expect. Microsoft, with assurances that it’s the Next Big Cash Cow, has tried to lead third-party developers to the promised land of Metro apps — but as evinced by the severe lack of Metro apps, developers clearly aren’t taking the bait. "

    Yup.  I do mobile development and I'm in regular contact with about 40 other mobile developers. None of them plan to build apps for Windows 8 – None. Yet all other platforms are being built for… iOS, BlackBerry, Android, and even stuff for Samsung TVs.

  29. Jacob says:

    PS your comment system is atrocious!

    more from the article: http://www.extremetech.com/…/138701-windows-8-the-disastrous-result-of-microsofts-gutless-equivocation

    "With Windows 8, everyone can see that Microsoft is uncertain about the future of PCs — and uncertainty coming from one of the world’s largest companies is cripplingly contagious. By keeping the Desktop around — even on Windows RT, which can only run four desktop apps! — Microsoft is signalling to consumers, developers, specialists, stockholders, and employees that it hasn’t a clue what the future holds"

    Exactly! Microsoft got p0wn3d by Apple and Google and is trying desperately to get into the tablet game – I applaud their efforts but this multi-desktop OS is so full of fail it isn't funny anymore.  Big enterprise apps have already declared NO support for Metro IE, no SAP, no WebEx, no SalesForce, (LinkedIn is refusing to comment), no EDS, everyone has already bailed on "Metro on the Desktop" and Windows 8 is only just being released today.

    "It might have sounded like a good idea in the boardroom, but by shipping an operating system with an identity crisis Microsoft has put itself in an almost untenable position. Barring a miraculous intervention by third-party app developers, Windows 8 looks like it will be a jack of all trades, but master of none. On mobile, iOS and Android’s ecosystems will prevail; on desktop, Windows 7 will be hard to supplant.

    Instead of hedging its bets, Microsoft should have risked it all on an honest-to-God tablet operating system. Sure, it might’ve failed, but at least it wouldn’t've poisoned the incredibly lucrative Windows well."

    R.I.P. Microsoft it was a fun ride while it lasted.

  30. EricLaw [ex-MSFT] says:

    @Xavier: You can use Group Policy to set the default launch experience for IE (the UI options seen at Tools > Internet Options > Connections > "Choose how you open links" and "Open Internet Explorer tiles on the desktop").

    This doesn't "disable" MetroIE, per-se, but it will only open in Metro mode in very narrow circumstances, e.g. when using the Win8 Search Charm.