23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The yellow bars indicate execution of the app’s JavaScript—that is, time spent inside the renderer.<br />

The beige bars indicate the time spent in DOM layout, and aqua bars indicate actual rendering to the<br />

screen. As you can see, when elements are added one by one, there’s quite a bit of breakup in what<br />

code is executing when, and the kicker here is that most display hardware refreshes only every 10–20<br />

milliseconds (50–100Hz). As a result, there’s lots of choppiness in the visual rendering.<br />

After making improvements, the chart can look like the one below, where the app’s work is<br />

combined in one block, thereby significantly reducing the DOM layout process (the beige):<br />

As for all the other little bits in these graphics, they come from the performance tool called XPerf<br />

that’s part of the Windows SDK (see sidebar). Without studying the details, what ultimately matters is<br />

that we understand the steps you can take to achieve these ends—namely, the different forms of<br />

renderers that you can employ as demonstrated in the sample.<br />

Sidebar: XPerf and msWriteProfilerMark<br />

The XPerf tool in the Windows SDK, which is documented on Windows Performance Analysis<br />

Tools, can very much help you understand how your app really behaves on a particular system.<br />

Among other things, it logs calls you make to msWriteProfilerMark, as you’ll find sprinkled<br />

throughout the WinJS source code itself. For these to show up in xperf, however, you need to start<br />

logging with this command:<br />

xperf –start user –on PerfTrack+Microsoft-IE:0x1300<br />

and end logging with this one, where is any path and filename of your<br />

choosing:<br />

xperf –stop user –d .etl<br />

Launching the .etl file you save will run the Windows Performance Analyzer and show a graph<br />

of events. Right-click the graph, and then click “Summary Table”. In that table, expand<br />

Microsoft-IE and then look for and expand the Mshtml_DOM_CustomSiteEvent node. The Field3<br />

column should have the text you passed to msWriteProfilerMark, and the Time(s) column will<br />

help you determine how long actions took.<br />

227

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!