суббота, 14 апреля 2012 г.

Understanding Differences in Hardware Acceleration through Paintball

While most modern browsers now support hardware acceleration, the quality of implementations varies greatly between browsers. Hardware acceleration is more than just a checkmark. How a browser chooses to enable hardware acceleration has a direct impact on the performance and user experience of Web applications.

To highlight the quality and performance differences in hardware acceleration, let's look closely at the Paintball test drive, released with IE 10 Platform Preview 1. Paintball uses HTML5 Canvas to simulate shooting paintballs against a wall. Paintball demonstrates how quickly images compose an entire scene. Many other HTML5 Canvas performance examples on the web just measure how quickly the same image can be drawn on the screen.

Paintball draws an entire scene as quickly as possible. At its end, you'll see two numbers. The first is how long drawing the entire scene took in seconds; the second is the number of paintballs fired per minute. In this test, more paintballs in a shorter time is better.

Screen shot of Paintball demo rendered in IE10 Platform Preview 1
Screen shot of Paintball demo rendered in IE10 Platform Preview 1
How Paintball Works

We wanted Paintball to be a general purpose Web application for painting any phrase with any color of paintball. To this end, Paintball programmatically generates paint splatters at runtime based on the specified RGB values. Programmatically manipulating images at runtime is a common scenario for emerging HTML5 Web applications.

Paintball starts by drawing a solid rectangle which is the color of the paint splatter.

Rendering paint splatter effect - step 1

Paintball uses a sprite sheet to hold the frames of the splatter animation:

Paint splatter effect sprite strip

Paintball decides how large the resulting splatter should be, and draws a frame from the sprite sheet using the destination-in composition mode. This causes the pixels being drawn to mask the current contents of the canvas.

Rendering paint splatter effect - step 2

By generating the graphics on the client, Web developers are able to build and download fewer images. This is a great approach for programmatically changing the color of an image.

The paintballs are created in a canvas which is not visible on the screen, and then drawn to the primary display canvas. Using a secondary, off-screen canvas to compose the effects improves performance quite a bit, in all browsers, by using composition operations only while the animation is in progress. Once the animation has reached its final frame (paint fully splattered), we can use a cached view of the secondary canvas when drawing the full scene.
Quality Differences

Paintball uses the same HTML5 markup for all browsers as specified by the HTML5 Canvas specification. Although all modern browsers now support these API’s, the quality differences are extremely noticeable. Here’s a visual comparison of the rendering differences:

Visual comparison of Paintball demo in Chrome 12, Firefox 4, IE 10 and Safari 5

You'll notice the following differences:

    * Chrome 12 does not draw the paint splatters correctly because Chrome does not implement the HTML5 Canvas composition modes according to the HTML5 specification.
    * Firefox 4 renders the scene correctly.
    * Internet Explorer 9 and Internet Explorer 10 render the scene correctly.
    * Safari 5 shares the paint splatters rendering artifacts with Chrome. Additionally, Safari does not yet support WOFF fonts.

These differences capture the kinds of problems that developers face building sites that look and work consistently across browsers. Developers want to use the same markup and experience interoperable results. While these bugs might seem minor (and shouldn't be hard to fix), they represent the quality issues across browsers that make developers resort to plug-ins or lower their expectations for sites.
Performance Differences

The performance differences between implementations are even more striking. For our testing we used the same mid-range configuration that we have used throughout the last year. Here’s how quickly these modern browsers, which all have some degree of hardware acceleration, compose the scene (on Windows 7):
    Chrome 12     Firefox 4     IE 10     Safari 5
Seconds
(lower is better)     516.14     100.17     11.35     68.11
Paintballs per minute
(higher is better)     10.11     52.11     459.95     76.64

Graph showing time Paintball demo takes to complete in Chrome 12, Firefox 4, IE 10 and Safari 5 Graph showing time Paintball's fired per minute in Chrome 12, Firefox 4, IE 10 and Safari 5
What’s Happening on the Hardware?

Let’s look at detailed performance traces to see how the different browsers use the CPU and GPU when animating a single paintball shooting and splattering onto the screen. The below results were generated using the Windows Performance Toolkit.

With Chrome 12 you’ll notice that it takes 3.7 seconds to shoot a single paintball. We can see that when the paintball first appears on the screen as a ball, there are lots of updates with moderate GPU and CPU utilization. Chrome is able to maintain almost real-time animation. Once the splatter effect (described above) starts to render, we see GPU and CPU utilization spike for several seconds. During this time, there are no screen updates, so the demo appears to freeze. Finally, the browser catches up and the scene finishes rendering.

Performance chart of a single paintball being shot in Chrome 12. Shows CPU time, GPU time, and Visual Updates.

Firefox 4 handles this scene quite well in 0.550 seconds. CPU and GPU utilization is fairly steady throughout the animation although the CPU activity does increase as the splatter effect is rendered. Screen updates occur predictably, rendering 19 frames during the rendering of the scene.

Performance chart of a single paintball being shot in Firefox 4. Shows CPU time, GPU time, and Visual Updates.

IE 10 renders the scene quite smoothly, in the shortest amount of time (0.475 seconds) and with the most frames. From the below graph, you can see how CPU and GPU utilization are lower than with Firefox, and the screen updates occur more frequently and at more regular intervals.

Performance chart of a single paintball being shot in IE 10. Shows CPU time, GPU time, and Visual Updates.

Performance in Safari 5 can be misleading from the CPU/GPU measurement perspective. While the GPU utilization is lower, and that screen updates occur frequently at regular intervals, nothing appears to be happening on the screen. That’s because Safari is telling the GPU to paint the same image over and over again. Safari only draws a few images to the screen and then jumps to the final frame without any animation occurring. Safari feels hung and unresponsive during this time.

Performance chart of a single paintball being shot in Safari 5. Shows CPU time, GPU time, and Visual Updates.

The graphs above show a single paintball splatter – a small slice in the overall work done to render the entire Paintball demo. While most browsers can handle a single paintball well, many of the browsers have a difficult time scaling to dozens of paintballs. For example, Firefox renders a single splatter fairly well (almost as fast as IE 10). However, when faced with a higher load in the full demo experience, performance in Firefox slips to about 20% of Internet Explorer 10.

Here’s the total CPU time, GPU time, and visual updates across browsers.

Comparison of CPU time consumed for a single paintball being fired in Chrome 12, Firefox 4, IE 10 and Safari 5. Comparison of GPU time consumed for a single paintball being fired in Chrome 12, Firefox 4, IE 10 and Safari 5. Comparison of Visual Updates during a single paintball being fired in Chrome 12, Firefox 4, IE 10 and Safari 5.

Summary

Browsers with full hardware acceleration and fully interoperable implemenations of HTML 5 features deliver a better experience for Web developers and end users.

We hope this look into the internals of Paintball will help you better understand the different quality and performance characteristics across browsers, particularly in relation to HTML5 Canvas and composition modes. It’s an exciting time to be developing graphically rich Web experiences!

—Seth McLaughlin, Program Manager, Internet Explorer Performance Team

IE9 Compat Inspector

With IE9 now released, we want you to serve IE the same markup as you do for other browsers, and make sure your site works great running in IE9 standards mode. We recently blogged about preparing your site for IE9, and you can check out the Internet Explorer 9 Compatibility Cookbook for lists of changes that may impact your site or the Internet Explorer 9 Guide for Developers for a more complete list of what's changed. Today we are introducing a new resource that can help speed up the process of preparing your site: Compat Inspector.
About Compat Inspector

Compat Inspector is a JavaScript-based testing tool that analyzes your site while it runs. Compat Inspector reports patterns of interaction which cause issues in standards mode. This allows you to identify problems quickly without memorizing a bunch of documentation or searching through the entirety of your site's code. We developed Compat Inspector during the course of IE9 to speed up the process of recognizing common issues across different sites. Along the way many members of the IE team contributed to the set of test cases that make up the rules in Compat Inspector. Now we're making it all available to you. Check out the Compat Inspector Test Drive to try it out before using it on your own site.

Compat Inspector is designed to help sites migrating to IE9 Standards Mode, not those running in legacy modes. You may still need to refer to the above documentation for some issues. The best pattern is to use Compat Inspector first, then fall back to the documentation if nothing is found.
How do I use it?

To use Compat Inspector, add the following script before all other scripts on each page you want to test:



Note: If you have Fiddler, you can automatically load Compat Inspector on all pages you visit by adding this snippet to your FiddlerScript (which is particularly helpful if your page uses frames). I recommend installing the FiddlerScript Editor extension if you don’t already have it.

After you have the above script in place, open your page in IE9 and start using it. Explicitly test any interactions known to be working incorrectly (only executed code is analyzed). Compat Inspector will keep a running total of all errors and warnings associated with detected issues. A summary view in the upper right hand corner of the page displays the results:

A screenshot of the Compat Inspector summary view showing one error, zero warnings, and zero info messages.

Click on this view to expand it and obtain detailed information about each detected issue with links to relevant documentation:

A screenshot of the Compat Inspector details view. The view has three tabs: "Message Log", "Tests", and "Verifiers". It also contains a link for "Help". The "Message Log" tab is focused. It contains four checkboxes labeled "Show Errors", "Show Warnings", "Show Info Messages", and "Show Duplicates". All checkboxes are checked except for "Show Duplicates". In the content area below the checkboxes one error message is displayed. The message reads "ERROR: The createElement API no longer accepts angle brackets '<>'. This is a deliberate change made in IE9 Standards Mode for interoperability with other web browsers and compliance with DOM Level 3 Core." Additionally the message contains links to resources to help resolve the issue and two unchecked checkboxes labeled "Verify" and "Debug".

Most errors and warnings also provide two additional actions for further investigation: "Verify" and "Debug."
"Verify" Workflow

Some test cases have built-in "verifiers" that emulate legacy behavior. This allows you to confirm the root cause of an issue before making any changes to your code.

Prerequisite: Compat Inspector is opened in the detailed information view and displaying an error or warning message containing a checkbox labeled "Verify."

   1. Click the "Verify" checkbox for the issue you want to confirm
      Another screenshot of the "createElement" error message. This time the checkbox labeled "Verify" is checked.
   2. Refresh the page (You'll see a notification that the verifier has been enabled)
      A screenshot of an informational message stating "INFO: The verifier The createElement API no longer accepts angle brackets '<>'. has been enabled. This message contains a single checkbox labeled "Verify" which is checked.
   3. Repeat the steps that originally triggered the error or warning
   4. If the issue still occurs
         1. If error or warning messages are still displayed, repeat steps 1-4 for each remaining message
         2. Otherwise, Compat Inspector cannot fully identify this issue. Refer to the IE9 documentation for additional help.
   5. Otherwise, you've identified the root cause of the issue
         1. Uncheck all "Verify" checkboxes
            Another screenshot of the "createElement" informational message. This time the checkbox labeled "Verify" is unchecked.
         2. Refresh the page
         3. Follow the "Debug" Workflow below to locate the source of each message in your code
         4. Follow the instructions in the displayed error/warn messages to resolve the issue
         5. Note: Also look for any "if IE" checks controlling the execution of the problematic code. IE9 typically works best when given the same code as other modern browsers.

"Debug" Workflow

Compat Inspector can also help you isolate where in your code things went wrong via the "debug" feature.

Prerequisite: Compat Inspector is opened in the detailed information view and displaying an error or warning message containing a checkbox labeled "Debug."

   1. Click the "Debug" checkbox for the issue you want to investigate
      Another screenshot of the "createElement" error message. This time the checkbox labeled "Debug" is checked.
   2. Open the F12 developer tools by pressing the F12 key
      A screenshot showing the initial view of the F12 tools.
   3. Switch to the "Script" tab
      A screenshot showing the "Script" tab as focused in the F12 tools.
   4. Click "Start debugging"
      A screenshot showing the "Start Debugging" button as focused in the F12 tools.
   5. Repeat the steps that originally triggered the error or warning (This will invoke the script debugger)
      A screenshot showing a snippet of JavaScript paused in the F12 tools. The code contains the JavaScript statement "debugger;" with a comment informing readers that the break point was triggered by Compat Inspector with instructions to look at the next item up in the call stack.
   6. Switch to the "Call stack" sub-tab located in the right half of the F12 developer tools
      A screenshot of the "Call stack" sub-tab of the "Script" tab in the F12 tools. The call stack contains two entries (from top to bottom): "inspectorFunction" and "JScript global code". The entry "inspectorFunction" is selected.
   7. Double-click the entry visually below the highlighted entry in the call stack
      Another screenshot of the "Call stack" sub-tab of the "Script" tab in the F12 tools. This time the entry "JScript global code" is selected.
   8. Look over at the left hand side of the F12 developer tools to see the code that triggered the error or warning
      A screenshot showing the JavaScript code: document.createElement("
").

How does it work?

Compat Inspector uses features introduced in IE9. At its core, Compat Inspector overrides native APIs using ECMAScript 5th edition getters/setters and depends on the browser to correctly expose APIs per WebIDL. Compat Inspector then uses these overrides to track interactions between the page and the native platform. This allows it to report issues at runtime as the problem code is executed.

The rest of the Compat Inspector infrastructure makes use of various other new features as needed. Some examples include DOM Level 3 Core APIs, DOM Level 3 Events APIs, and CSS3 Border Radius. Compat Inspector also depends on features introduced in IE8 such as HTML5 Local Storage, HTML5 Cross-Document Messaging, native JSON support, and Selectors API.
My site works, now what?

Remove the Compat Inspector script from all your pages before publishing. Compat Inspector is a test tool and should not be used in production. After that, keep an eye on the IE blog; we may have new test cases to share in the future.

—Tony Ross, Program Manager, Internet Explorer

IE 9.0.6 Available via Windows Update

The April 2012 Cumulative Security Update for Internet Explorer is now available via Windows Update. This security update resolves five privately reported vulnerabilities in Internet Explorer. The most severe vulnerabilities could allow remote code execution if a user visits a specially crafted Web page using Internet Explorer. An attacker who successfully exploited any of these vulnerabilities could gain the same user rights as the local user. Users whose accounts are configured to have fewer user rights on the system could be less affected than users who operate with administrative user rights.

This security update is rated Critical for Internet Explorer 6, Internet Explorer 7, Internet Explorer 8, and Internet Explorer 9 on Windows clients and Moderate for Internet Explorer 6, Internet Explorer 7, Internet Explorer 8, and Internet Explorer 9 on Windows servers. For more information, see the full bulletin.

Most customers have enabled automatic updating and do not need to take any action. We recommend that customers, who have not enabled automatic updating, enable it (Start Menu, type “Windows Update”). We recommend that administrators, enterprise installations, and end users who want to install this security update manually, apply the update immediately using update management software or by checking for updates using the Microsoft Update service.

—Tyson Storey, Program Manager, Internet Explorer

пятница, 6 апреля 2012 г.

Pinned Sites in Windows 8

The Windows 8 Start screen is the best place to find and stay connected to all your favorite apps and content. App tiles are alive with activity and show you fresh and tailored content so you know what’s new in your world.
We’ve written about Internet Explorer 10’s Metro style browsing experience on Windows 8. This post describes in detail IE10’s pinned sites and their availability on the Windows 8 Start screen—complete with site-centric visuals and badge notifications to let you know there is new content. We’ll also walk through the Web developer details to support pinned sites.
The following video shows pinned sites in action on Windows 8 Consumer Preview.

Pinned Sites in Windows 8

Pinned Sites – More than Favorites

Consumers on Windows spend most of their time on the Web and we know from Windows opt-in telemetry (officially, the Microsoft Customer Experience Improvement Program), that they go back to the same set of sites time and again. Pinned sites on Windows 8 make it fast and easy to immediately get to your sites. With badge notifications, site tiles come alive with up-to-date information and help you know when new content is available.
Developers can utilize pinned sites to better connect their site with their users and promote their site’s brand directly in the Windows start screen. We found that sites that used this feature with IE9 on Windows 7 see anywhere from a 15 percent to 50 percent increase in site visits. In Windows 8 the experience for consumers is even better with site tile updates, even when you don’t have the site open in the browser.
The following two screen shots illustrate pinned site tiles and badge notifications.
Pinned sites on the Start screen showing site-centric visuals and badge notifications
Pinned sites on the Start screen showing site-centric visuals and badge notifications
Example of a badge notification on a pinned site’s tile
Example of a badge notification on a pinned site’s tile

Site-Centric Visual on the Pinned Site Tile

As a Web developer, you can provide a site icon (favicon) that IE10 uses throughout the browser to represent the site, in the address bar, on the new tab page, and on the Start screen. IE10 uses the large site icon (32 x 32 pixels) to identify the site when pinned to the Start screen the same way that IE9 used it for pinning to the task bar.
Screen shot of pinning a site with Metro style IE10 showing a preview of the site’s tile
Screen shot of pinning a site with Metro style IE10 showing a preview of the site’s tile
IE10 extracts the dominant color from the icon and automatically uses it as the background color for the Start screen tile.
One tool for creating icons is x-icon editor. Use it to create the 32x32 icon for your site. It can also convert an image to the icon file format (.ico). Then associate the .ico using traditional favicon markup:
<link href="testdrive.ico" rel="shortcut icon" />

Badge Notifications That Update In the Background

Windows 8 can poll for updates for pinned tiles on the Start screen. This works well for lightweight notifications such as new messages from other users (email & social networking), new discounts on a shopping site, new articles on a newsfeed etc.
With Internet Explorer 10 and Windows 8, you can offer badge notifications directly on your pinned site tiles. This means users get updates to their sites without the site being open in the browser. As an example, pin the Fresh Tweets demo using IE10 on Windows 8 Consumer Preview. The pinned site tile updates on a regular basis and notifies the user when there are new tweets available.
Background notifications require site-provided components. These are: (1) Badge Notification XML, an XML response that describes the badge notification for Windows, and (2) Pinned Site Meta Tags, Web page markup that points to the location which Windows should poll for notifications and the frequency of polling.

Badge Notification XML

Windows handles the polling and drawing of badge notifications. Windows polls the badge notification XML that describes the visual for the pinned site tile. The badge XML schema defines this simple XML response. For example, to update the tile with the number “3,” you send the following XML:
xml version="1.0" encoding="utf-8" ?>
<badge value="3"/>
Badges can be numbers or glyphs, such as ‘alert’ and ‘new message’ indicators. For a full list of what a badge can display, see Choosing a badge image on MSDN.

Pinned Site Meta Tags

The next step is associating the badge notification XML to the Web page. IE10 uses the meta tag “application-name” to determine if the Web page supports pinned sites capabilities like notifications and jump lists. To support badge notifications, include a new meta-tag in your markup with the URL of the badge notification XML and the frequency with which Windows should request it. IE checks to see if the “msApplication-badge” meta tag is present on the page at time of pinning, as well as on subsequent launches of the site from the pinned site tile.
<meta name="msapplication-badge" value="frequency=360;polling-uri=http://ietestdrive2.com/PinnedSites/TweetCounter/microsoft/360" />
The value parameter has two parts: polling-uri (required) and frequency (optional).
polling-uri is the absolute URI from which Windows requests the simple XML document defined above.
frequency is an optional number of minutes between updates and must be one of the following values:
  • 30 (Windows will poll the URI every 30 minutes)
  • 60 (1 hour)
  • 360 (6 hours)
  • 720 (12 hours)
  • 1440 (1 day. This is the default.)
If frequency is omitted or has a value other than one listed above, it defaults to daily updates (1440 minutes).

Developer APIs for updating Badge Notifications

You can also clear and refresh the site tile badge from the Web page directly to ensure that the site tile is up-to-date.
When a user launches the pinned site tile through the Start screen, the Web site is running in its own session called SiteMode and can use the following JavaScript functions to update the badge.
window.external.msSiteModeClearBadge() clears the badge notification on the tile. In the Fresh Tweets demo, when the user receives a notification and taps on the tile to launch the browser, the Web page uses msSiteModeClearBadge() to clear the notification from the tile. The next time the tile lights up with a badge update, the user knows there is new content.
window.external.msSiteModeRefreshBadge() calls Windows to update the badge on the site using the polling URI. As an example, the user sees a pinned site tile indicating three unread messages and clicks on the tile to return to the site. If he or she reads only the first update, you can trigger an update so the badge reflects the correct read/unread count of two.
In Windows 8 Consumer Preview, these two APIs only function on sites running in the Local intranet or Trusted sites zones. This will be fixed in the next preview. To test these APIs in the Consumer Preview on your own site, add its domain to the Trusted sites list using the Security tab of the Internet Properties dialog.

Desktop Taskbar Notifications

Notifications that appear as icon overlays for pinned sites on the desktop taskbar will continue to work for Windows 8 and IE10 on the desktop. This form of notification is not available on the pinned site for the Windows 8 Start screen. Windows 8 handles notifications for all tiles on the Start screen and does so in a battery-efficient way.

Jump Lists to Quickly Navigate Within the Site

Many top sites such as NYTimes.com, CNN.com, and Amazon.com support IE9 pinned sites features such as jump lists to get to a specific task or part of a site. With IE10, jump lists are available as part of the navigation bar for a touch-friendly way to navigate the site.
When the user launches the site from the Start screen, the pin button shows that there are jump lists available for this site:
Screen shot showing the Fresh Tweets Demo’s jump list
Screen shot showing the Fresh Tweets Demo’s jump list
The jump list displayed is the same as IE9 displays on the Windows 7 taskbar.
You can add static tasks to your site’s jump list via page markup (learn more) or dynamically based on user interactions (learn more). Badge and jump lists in Windows 8 are a site-centric feature. Each fully qualified domain name can have one and only one set of polling data and jump list data.

Conclusion

Internet Explorer 10 puts sites at the center of the experience through integration with the Windows 8 Start screen. Web developers can create site-centric visuals for pinned site tiles, share when there are new updates available for the site, and offer jump lists to navigate quickly around the site.
We look forward to you adding these simple features to your Web site to maximize their impact in Windows 8.
—Rahul Lalmalani, Program Manager, Internet Explorer