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.304879519774Date.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: 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.

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!

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.

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

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.

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.

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.

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.

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.

@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.

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.

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.

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.

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.

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.

"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.

"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."

@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.