Dot Net Perls

Visual Studio Tab Options

by Sam Allen

Problem

Replace spaces with tabs to optimize your markup files in Visual Studio 2008. What can we learn from Office 2007 about XML file size and efficiency? Find out what Microsoft's developers have to say, and view some benchmarks.

Solution

If you a project that parses thousands of XML files per day, you want to optimize the XML. Microsoft, in developing the Open XML (.docx, .xlsx) format, investigated XML performance with tag name length.

Minifying XML

The term 'minifying' is applied to CSS and JavaScript on the web, but it also can work for XML. In Visual Studio, a tab character is usually equal to 4 spaces. So, we can save a lot of space by using tabs instead of spaces.

  1. In Visual Studio
    Go to Tools > Options... This will bring up the Options window we know and love.
  2. Click Text Editor
    In the left, there are a bunch of arrows and labels. Click on Text Editor, and then go to XML.
  3. Indent size
    This is where you can save bytes. Choose 'Keep tabs' if it isn't already selected. This will decrease the size of XML files you edit.

Tabify selected lines

Here we can change lines in Visual Studio to use tabs. This will reduce file size in your XML files on the selection. Go to Edit > Advanced. There are many useful options here.

Does it really help?

Yes. However, unless your application is really huge, it won't be noticeable. Just for kicks, I measured a sitemap XML file with spaces, and then with tabs. The results shouldn't have surprised me, but I guess they did. (If you're counting, the results were 30967 bytes for spaces, and 25891 bytes for tabs.)

Conclusion

For a task that takes a couple minutes to complete, the effect is worthwhile here. Obviously, a format such as Open XML has very strict requirements, but applying that research to all projects is smart. Use Tabify and Untabify wisely and always keep in mind the coding guidelines of your project.

Dot Net Perls
About
Sitemap
Source code
RSS
Tools
Visual Studio Post-Build, Pre-Build Macros
Visual Studio TODO Comments
Visual Studio Settings.settings Use
Visual Studio 2008 Review
Rounded Corners Tutorial
Recent
Pi
NGEN Installer Class
List Element Equality
DateTime Tips and Tricks
Remove HTML Tags From String
© 2008 Sam Allen. All rights reserved.