Performance Optimization For XPS Documents Feng Yuan Principal

  • Slides: 26
Download presentation
Performance Optimization For XPS Documents Feng Yuan Principal Software Development Engineer Microsoft Corporation

Performance Optimization For XPS Documents Feng Yuan Principal Software Development Engineer Microsoft Corporation

Key Takeaways Raise awareness of performance issues Demonstrate how to XPS documents XPS document

Key Takeaways Raise awareness of performance issues Demonstrate how to XPS documents XPS document measure optimize

Agenda Performance issues with XPS documents Metrics for XPS documents XPS measuring tool Optimizing

Agenda Performance issues with XPS documents Metrics for XPS documents XPS measuring tool Optimizing XPS documents Fixed. Page Font Image Call To Action

XPS Document Life Cycle Generation Transmission Archiving Searching Viewing Printing Discarding

XPS Document Life Cycle Generation Transmission Archiving Searching Viewing Printing Discarding

Activities On XPS Document Transmission Zip container decoding Stream decompression Object model building Document

Activities On XPS Document Transmission Zip container decoding Stream decompression Object model building Document structure construction Rendering Conversion Searching

Impact Of Non-Optimized XPS Larger storage requirement Larger network bandwidth requirement Slower downloading Slower

Impact Of Non-Optimized XPS Larger storage requirement Larger network bandwidth requirement Slower downloading Slower viewing Slower printing Unable to view or print

Performance Measures XPS document size Loading time Memory consumption Rendering time Searching time

Performance Measures XPS document size Loading time Memory consumption Rendering time Searching time

Performance Metrics Container: Original size, compression, number of streams, order of streams, interleaving Markup:

Performance Metrics Container: Original size, compression, number of streams, order of streams, interleaving Markup: Number of elements, number of attributes, nesting of opacity, area of opacity, sharing of objects Image: Resolution, pixel format, file format, compression Font: Tables, glyphs

XPS Package Relationships XPS Package Common Package Parts Core Properties Thumbnail Signature Origin Signature

XPS Package Relationships XPS Package Common Package Parts Core Properties Thumbnail Signature Origin Signature X 509 Certificate Required or Recommended Parts Optional Parts Resources Relationship Fixed Document Sequence Fixed Document Fixed. Page Document Structure Thumbnail Font Image Resource Dictionary

Measuring XPS: Xps. Stat Type Count Original Compressed Ratio fixedpage 453 116, 521, 006

Measuring XPS: Xps. Stat Type Count Original Compressed Ratio fixedpage 453 116, 521, 006 5, 912, 474 95% package. relationships 434 573, 558 164, 871 71% properties 1 673 342 49% fixeddocument 1 289, 702 13, 756 95% 20 1, 647, 572 576, 144 65% 492 1, 042, 993 992, 681 5% fixeddocumentsequence 1 320 160 50% documentstructure 1 179, 194 13, 154 93% /[Content_Types] 1 1, 023 331 68% 195, 978 0% 120, 452, 019 7, 869, 891 93% opentype Image ZIP Structure Summary 1, 410

Fixed. Page Main contributor for long document Compression ratio: 95% 500 elements for normal

Fixed. Page Main contributor for long document Compression ratio: 95% 500 elements for normal page 10 K to million elements for complex page Page Size Glyphs Path Image Opacity. Mask 1. fpage 10. fpage 453. fpage Summary 1, 690, 254 530 237, 266 116, 521, 006 57 0 352 87, 179 1, 037 0 15 111, 593 1, 994 0 0 11, 653 997 0 0 5, 690

Fonts Main contributor for short document Compression ratio: 40% to 90% Larger document if

Fonts Main contributor for short document Compression ratio: 40% to 90% Larger document if not embeddable Typeface Size Comp. Size Char Used Elements Original Glyphs Verdana Italic 60, 668 21, 765 3, 287 76 893 Arial Bold 81, 356 16, 371 320 1[32] 1, 674 Courier New Regular 71, 824 41, 569 19, 896 104 1, 318 MS Mincho Regular 209, 844 19, 532 4 38 17, 807 Wingdings Regular 24, 052 9, 623 1 1[232] 226 Verdana Regular 73, 020 29, 075 49, 436 99 893

Images Contributing to all documents Compression ratio: 0% to 5% Implementing non-embeddable text Choose

Images Contributing to all documents Compression ratio: 0% to 5% Implementing non-embeddable text Choose right size, format, Image Size Comp. Size Width Height Format Usage compression thumbnail. jpeg 6, 538 image_0. png 143 image_2. png 145 image_348. jpg 33, 579 image_96. png 10, 568 5, 832 131 136 33, 277 10, 489 197 1 2 392 474 256 1 1 611 205 Bgr 24 Bgra 32 Bgr 24 Indexed 8 4 182 1 1 Color 206 black 2 121

Optimizing Fixed. Page Use simple syntax Solid Color Brush: Fill=“#FFFFFF” Path: Data=“M 0, 0

Optimizing Fixed. Page Use simple syntax Solid Color Brush: Fill=“#FFFFFF” Path: Data=“M 0, 0 h 100 v 100 h-100 z” Use less costly representation Single color image à solid color Same color gradient à solid color Image with same rows/columns à single row/column Remove non-visible elements Empty path, glyph elements Opacity=0, totally clipped, out of bound, totally covered

Optimizing Fixed. Page Remove default value/redundancy Opacity, Bidi. Level, Tile. Mode, Style. Simulation, Is.

Optimizing Fixed. Page Remove default value/redundancy Opacity, Bidi. Level, Tile. Mode, Style. Simulation, Is. Sideways Clipping larger than elements, same as paper bounds Canvas with single child, no attributes Glyphs. Indices optional for simple mapping and layout Remove redundant paths/points in path geometry Reuse elements and attributes Resource and remote resource dictionary Brushes, Matrix. Transform, Path, Glyphs, Canvas Use Render. Transform to create more reusable parts

Optimizing Fixed. Page Remove default value/redundancy Opacity, Bidi. Level, Tile. Mode, Style. Simulation, Is.

Optimizing Fixed. Page Remove default value/redundancy Opacity, Bidi. Level, Tile. Mode, Style. Simulation, Is. Sideways Clipping larger than elements, same as paper bounds Canvas with single child, no attributes Glyphs. Indices optional for simple mapping and layout Remove redundant paths/points in path geometry Reuse elements and attributes Resource and remote resource dictionary Brushes, Matrix. Transform, Path, Glyphs, Canvas Use Render. Transform to create more reusable parts

Optimizing Fixed. Page Merge Glyphs/Path elements Merge same size/font glyphs on the same line

Optimizing Fixed. Page Merge Glyphs/Path elements Merge same size/font glyphs on the same line Merge simple paths with the same stroking/filling Merge tiled images Replace simulated gradient fill with real gradient More complex optimization Brush algebra: (red, 0. 5) * (red, 0. 5) = (red, 0. 75) opacity 1 * (rgb, opacity 2) = (rgb, opacity 1 * opacity 2) Selective rasterization Visual. Brush for hatching, stencils

Sample: Markup Optimization <Fixed. Page. Resources> <Resource. Dictionary> <Radial. Gradient. Brush x: Key="black" Center="0.

Sample: Markup Optimization <Fixed. Page. Resources> <Resource. Dictionary> <Radial. Gradient. Brush x: Key="black" Center="0. 5, 0. 5" Radius. X="0. 5" Radius. Y="0. 5" Gradient. Origin="0. 2, 0. 2"> <Radial. Gradient. Brush. Gradient. Stops> <Gradient. Stop Color="#ff 505050" Offset="0" /> <Gradient. Stop Color="#e 0080808" Offset="1" /> </Radial. Gradient. Brush. Gradient. Stops> </Radial. Gradient. Brush> <Path. Geometry x: Key="circle" Figures="M 0, -0. 5 A 0. 5, 0. 5 0 1 1 0, -0. 5" /> <Path. Geometry x: Key="grid 33" Figures="m 0, 0 h 2 M 0, 1 h 2 M 0, 2 h 2 M 0, 0 v 2 M 1, 0 v 2 M 2, 0 v 2" /> </Resource. Dictionary> </Fixed. Page. Resources> <Canvas Render. Transform="48, 0, 0, 48, 48"> <Path Data="m 0. 5, 0. 5 h 3 v 3 h-3 z" Fill="#E 0 C 000" /> <Path Data="{Static. Resource grid 33}" Stroke="#000000“ Stroke. Thickness="0. 03" Render. Transform="1, 0, 0, 1, 1, 1"/> <Path Data="{Static. Resource circle}" Fill="{Static. Resource black}“ Render. Transform="0. 9, 0, 0, 0. 9, 1, 1"/> </Canvas>

Optimizing Fonts Subset fonts, preferably per document Remove/replace barely used fonts Substitute fonts when

Optimizing Fonts Subset fonts, preferably per document Remove/replace barely used fonts Substitute fonts when not embeddable Share glyph bitmaps/outlines Font tables of limited usage GSUB, GPOS, kern EBDT, hdmx, vdmx Consider rearrange glyph indices

Sample: Font Optimization Vista, simkai. ttf, 28, 562 glyphs, 11 mb Subset with围棋, 183

Sample: Font Optimization Vista, simkai. ttf, 28, 562 glyphs, 11 mb Subset with围棋, 183 k, 55 k compressed hmtx 58 k, loca 57 k, vmtx 57 k, glyf 690 b Convert to path geometry: 1148 b+1260 b <Path. Geometry x: Key="wood“ Figures="M 173, -311 q 23, -5 35, -5 12, 0 19, 7 7, 7 -6, 12 -13, 5 -48, 12 l 0, 70 30, 2 46, 11 17, 8 12, 23 -4, 15 -17, 11 -13, -5 -41, -33 0, 70 -3, 128 -2, 57 -10, 92 -8, 35 -21, 8 -13, -27 -6, -58 7, -32 12, -72 5, -40 5, 122 -31, 56 -56, 87 -24, 30 -56, 53 -31, 22 -3, -9 28, -32 58, 84 31, -52 45, -98 l-49, 9 q-22, 2 -42, -8 -19, -11 13, -14 33, -4 90, -16 0, -49 -2, -85 -1, -36 -14, -55 -13, -19 21, -8 34, 10 27, 30 -7, 20 -9, 114 z" /> <Path Data="{Static. Resource wood}" Fill="#C 00000 FF" Render. Transform=“ 5 0 0 5 2000 2800" />

Optimizing Images Share duplicated images (crc 32) Stitch banded images Single color/same row/same column

Optimizing Images Share duplicated images (crc 32) Stitch banded images Single color/same row/same column image Pick the right size, trim image Pick the right color depth Pick the right image format Adjust compression Opacity. Mask merge with brush, remove rgb

Sample: Image Optimization <Path Data="M 15. 6, 91. 56 L 199. 8, 186 L

Sample: Image Optimization <Path Data="M 15. 6, 91. 56 L 199. 8, 186 L 15. 6, 186 Z" Clip="M 0, 0 L 720, 540 L 0, 540 Z "> <Path. Opacity. Mask> <Image. Brush Image. Source=“image_3. png" Viewbox="0, 0, 512, 262" Tile. Mode="None" Viewbox. Units="Absolute" Viewport="0, 0, 1, 1"> <Image. Brush. Transform> <Matrix. Transform Matrix="184. 2, 0, 0, 94. 44, 15. 6, 91. 56"/> </Image. Brush. Transform> </Image. Brush> </Path. Opacity. Mask> <Path. Fill> <Image. Brush Image. Source=“image_4. png" Viewbox="0, 0, 512, 262" Tile. Mode="None" Viewbox. Units="Absolute" Viewport="0, 0, 1, 1"> <Image. Brush. Transform> <Matrix. Transform Matrix="184. 2, 0, 0, 94. 44, 15. 6, 91. 56"/> </Image. Brush. Transform> </Image. Brush> </Path. Fill> </Path>

Sample: Image (512 x 262) Name Quality Format Size image_3. png 1, 1 32

Sample: Image (512 x 262) Name Quality Format Size image_3. png 1, 1 32 bgra 47, 934 Image_4. png 1, 1 32 bgra 47, 877 Merge. png 1, 1 32 bgra 36, 805 Merge. wmp 1, 1 32 bgra 62, 908 Merge. wmp 0. 8, 1 32 bgra 35, 535 Merge. wmp 0. 8, 0. 8 32 bgra 2, 774 Merge. tiff 1, 1 32 bgra 53, 262 Merge. png 1, 1 8 indexed 19, 388 <Path Data="m 0, 0 h 1 v 1 h-1 z" Render. Transform="184. 2, 0, 0, 94. 44, 15. 6, 91. 56"> <Path. Fill> <Image. Brush Image. Source="merge 256. png" Viewbox="0, 0, 512, 262" Viewbox. Units="Absolute“ Viewport. Units="Absolute" Viewport="0, 0, 1, 1" /> </Path. Fill> </Path>

Call To Action Read OPC/XPS specifications Measure current XPS documents Experiment with alternatives Design/implement

Call To Action Read OPC/XPS specifications Measure current XPS documents Experiment with alternatives Design/implement better XPS generation Design/implement XPS optimization

Additional Resources XPS Related Web Resources Specification, white papers, download: http: //www. microsoft. com/xps

Additional Resources XPS Related Web Resources Specification, white papers, download: http: //www. microsoft. com/xps Blog: http: //blogs. msdn. com/xps Forum: http: //forums. microsoft. com/msdn/showforum. aspx? forumid=126 Related Sessions CLN-T 370 CLN-C 369 Practices CLN-C 372 XPSDrv: Best Practices using Print Verifier and XPSDrv Development Best XPS Document Optimization and Best Practices xpsinfo @ microsoft. com Technical Support prninfo @ microsoft. com

© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names

© 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U. S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.