Category Archives: Link/News

Book Review: High-Performance Windows Store Apps

I recently read Brian Rasmussen’s book High-Performance Windows Store Apps, and I think it’s an excellent companion to my own Writing High-Performance .NET Code.

It’s a good companion because while my book is all about the nitty-gritty details of .NET and how they effect performance, I don’t go too much into things at the UI layer. My perspective is much more systems and servers based, while Brian is coming at this from a UI/XAML focus. Brian covers a bunch of topics in a very good way.

The title specifically mentions “Windows Store” apps, but the principles and techniques described in here apply to any desktop/UI application, not just the types you see typically on tablets or phones. It’s worthwhile even if you develop just desktop apps.

Particular things I liked:

  • Chapter 3 – Designing for Performance – It presents a number of interesting performance scenarios, many of which aren’t obvious if you’re new to the new world of multi-device, cloud-connected apps we’re in. The discussion on resource management and prioritization was good too.
  • Chapter 4 – Instrumentation – A very good walkthrough of Event Tracing for Windows, which is what every developer needs to know these days, for tracking app events for performance, debugging, or just plain logging. Lots of good stuff here, and critical for all performance analyses these days.
  • Chapter 5 – Performance testing – Lots of good stuff in here I didn’t know about, particularly around building an automated performance testing environment for UI apps. Automation is critical, and this gives some good examples to get you on your way.

The book used the Windows Performance Recorder for most of its examples. It’s an excellent tutorial on how to make this tool useful to you, without getting bogged down into the complexities.

Overall, highly recommended. There are not very many guides on how to do performance engineering for XAML apps, and Brian writes a great one.

You can follow Brian on Twitter @kodehoved. Check out High-Performance Windows Store Apps at Amazon.

Appearance on .NET Rocks! Podcast

Carl and Richard put together a great podcast. .NET Rocks! has existed for years now and it’s amazing how many episodes they’ve published.

A couple of weeks ago, I had the privilege of recording their latest episode with them, #1041. We talked about a ton of interesting things like the importance of memory management, precise measurement, using the correct tools, not being afraid of the debugger, a little bit about Microsoft culture, and even LEGO!

Here is their description:

Carl and Richard talk to Ben Watson about his work around writing high performance .NET code. Ben talks about how the Bing team decided to use .NET code internally, which seems like an obvious choice for a Microsoft group, but it isn’t really – when milliseconds count, does .NET makes sense? Ben says it does, and he’s done the work to prove it. Ben’s book “Writing High Performance .NET Code” focuses not only on coding techniques, but also the larger practice of having a deep understanding of how .NET works, and the processes that take place to turn .NET code into machine code. The conversation also digs deeply into the need for performance measurement, especially Event Tracing for Windows. .NET can be fast when you do it right!

Give a listen. Subscribe in iTunes or listen on the web. Let me know what you think!

Announcing Writing High-Performance .NET Code

This blog has been silent for far too long. That’s because I’ve been heads-down on a side project for the last 10 months. I’d like to announce my latest technical book:

Writing High-Performance .NET Code

Cover-Tall-2000x2828

If you write managed code, you want this book. If you have friends who write managed code, they want this, even if they don’t know it yet.

Do you want your .NET code to have the absolute best performance it can? This book demystifies the CLR, teaching you how and why to write code with optimum performance. Learn critical lessons from a person who helped design and build one of the largest high-performance .NET systems in the world.

This book does not just teach you how the CLR works—it teaches you exactly what you need to do now to obtain the best performance today. It will expertly guide you through the nuts and bolts of extreme performance optimization in .NET, complete with in-depth examinations of CLR functionality, free tool recommendations and tutorials, useful anecdotes, and step-by-step guides to measure and improve performance.

Among the topics you will learn are how to:

  • Choose what to measure and why
  • Use many amazing tools, freely available, to solve problems quickly
  • Understand the .NET garbage collector and its effect on your application
  • Use effective coding patterns that lead to optimal garbage collection performance
  • Diagnose common GC-related issues
  • Reduce costs of JITting
  • Use multiple threads sanely and effectively, avoiding synchronization problems
  • Know which .NET features and APIs to use and which to avoid
  • Use code generation to avoid performance problems
  • Measure everything and expose hidden performance issues
  • Instrument your program with performance counters and ETW events
  • Use the latest and greatest .NET features
  • Ensure your code can run on mobile devices without problems
  • Build a performance-minded team

…and much more.

See http://www.writinghighperf.net for up-to-date information about the book. You can also like the Facebook page or subscribe to this blog to see updates.

The book is currently available via Amazon and Kobo. Barnes and Noble is pending. More retailers and formats will follow. See the Buy page to check for current availability.

I will also be posting some blog entries with topics inspired by the book, but weren’t quite a good fit.

New C# 4.0 How-To Review

Of course I  think you should go get my book, but so do other people. 🙂 Here’s a recent, good review of the book: C# 4.0 How-To by Ben Watson.

Some excerpts:

There were a couple things about this book that really compelled me.  The format (this is a first How-To book by Sams for me so I assume it goes across the board) was very much like a focused blog.  It was broken up into small posts about each topic.  The other thing that compelled me was the amount of code samples.

That is definitely the style I was going for and I don’t know if anyone else has picked up on that yet.

Instead, this is a book that you set on your desk and put post-its and dog ears for key sections that you use and use and use before you put the pattern to memory.

I myself use the book in that manner whenever I need a refresh on how to accomplish something.

Go get it from Amazon or B&N or other great bookstores everywhere!

First Bing.com commercial

Working on Bing.com for the last 9 months or so has been exhilarating. Finally, we can show the world the great stuff we’ve been doing. Here is (I think) the first TV commercial about Bing.com, running as of today.

I kissed Google goodbye more than a year ago and haven’t looked back. I think once people start using Bing, they’re going to do the same.

New apps and features from Live Search

I’ve been meaning to highlight a few of the cool things we’re doing in Live Search. I don’t have any direct involvement in the development of any of these—I just think they’re cool.

Answer Suggestions for IE8

IE8 is awesome, so go get it. Live Search has these things called Instant Answers where it can respond with succinct answers to your question, rather than just web pages that may have the answer. Good examples are weather and numeric conversions—you just want to know the answers, not necessarily follow links to find it.

You get normal search suggestions of course, but the cool thing is that the display of the instant answers is built right into IE8. You can type into the search box and have the answers returned right in the drop down as you type. Here are some samples:

Weather:answers_ie8_2 Solve math equations:

answers_ie8_1 There are a whole lot more kinds of answers. Maybe someday I’ll detail them.

Live Search Suggestions for Firefox

Firefox users haven’t been left out either. While there isn’t a full instant answers integration, Firefox does support search suggestions. You can download the plugin from the Firefox plugin directory.

firefox_live

Live Search for Windows Mobile

This is something I think really needs more publicity. I have a Samsung Saga i770, which I love. One of the first things I put on it was Live Search Mobile.

First of all, this thing has had speech recognition built-in since way before Google’s similar tools.

Easy to use, and optimized for your phone

It can easily find directions, gas prices, movies, traffics, maps, local businesses (by categories), and general web info. I use this app all the time.

There is custom software you can install for both Windows Mobile and Blackberry. It will work on the web for any other mobile phone that can get on the Internet.

And, by the way, it supports auto-suggest as well.

On your phone, you can go to wls.live.com to get it.

Related links:

NDepend: A short review

NDepend is a tool I’d heard about for years, but had yet to really dive into recently. Thanks to the good folks developing it, I was able to try out a copy and have been analyzing my own projects with it.

Here’s a brief run-down of my initial experience with it.

Installation

There is no installation file—everything is packaged into a zip. After running, I was greeted by a project selection screen, in which I created a new project and added some assemblies. NDepend main screen

Analysis

Once you have all the assemblies you want to analyze selected, you can run the analysis, which generates both an HTML report with graphics, and an interactive report that you can use to drill down into almost any detail of your code. Indeed, it’s almost overwhelming the amount of detail present in this tool.

One graph you see almost immediately is Abstractness Vs. Instability.

Abstractness vs. Instability

This is a good high-level overview of your entire project at the assembly level. Basically, what this means is that assemblies that are too abstract and unstable are potentially useless and should be culled, while assemblies that are concrete and stable can be hard to maintain. Instability is defined in the help docs in terms of coupling (internal and external), while abstractness is the ratio of abstract types to total types in an assembly.

This is followed by the dependency graph:

Dependency graph

After these graphics come lots of reports that dig into your code for all sorts of conditions.

For example, the first one in my report was “Quick summary of methods to refactor".” That seems pretty vague, until you learn how they determine this. All the reports in NDepend are built off of a SQL-like query language called CQL (Code Query Language). The syntax for this is extremely easy. The query and result for this report are:

NDepend_RefactorMethods

With very little work on my part, I instantly have a checklist of items I need to look at to improve code quality and maintainability.

There are tons of other reports: methods that are too complex, methods that are poorly commented, have too many parameters, to many local variables, or classes with too many methods, etc. And of course, you can create your own (which I demonstrate below).

Interactive Visualization

All of these reports are put into the HTML report. But as I said, you can use the interactive visualizer to drill down further into your code.

The first thing you’re likely to see is a group of boxes looking like this:

NDepend_Metrics

These boxes show the relative sizes of your code from the assembly level down to the methods. Holding the mouse over a box will bring up more information about the method. You can also change the metric you’re measuring by—say to cyclomatic complexity.

Another view, perhaps the most useful of all is the CQL Queries view. In this, you can see the results from all of hundreds of code queries, as well as create your own. For instance, I can see all the types with poor cohesion in my codebase:

NDepend_Cohesion

In this view, the CQL queries are selected in the bottom-right, and the results show up on the left. The metrics view highlights the affected methods.

Creating a query

Early in the development of my project, I named quite a few classes starting with a LB prefix. I’ve changed some of them, but I think there are still a few lying around and I want to change them as well. So I’ll create CQL query to return all the types that begin with “LB.”

   1: // <Name>Types beginning with LB</Name>
   2: WARN IF Count > 0 IN SELECT TYPES WHERE 
   3:  NameLike "LB" AND     
   4:  !IsGeneratedByCompiler AND 
   5:  !IsInFrameworkAssembly     

NDepend_LB That’s it! You can see the results to the right. It’s ridiculously easy to create your own queries to examine nearly any aspect of your code. And that’s if the hundreds of included queries don’t do it for you. In many ways, the queries are similar to the analysis FxCop does, but I think CQL seems generally more powerful (while lacking some of the cool things FxCop has).

 

VS and Reflector Add-ins

NDepend has a couple of extras that enable integration of Visual Studio (2005 and 2008) and NDepend and Reflector. When you right-click on an item in VS, you will have some additional options available:

NDepend_VSPlugin1

Clicking on the submenu gives you options to directly run queries in NDepend. Very cool stuff.

Summary and where to get more info

If you are at all interested in code metrics, and how good your code is behaving, how maintainable it is, you need this tool. It’s now going to be a standard part of my toolbox for evaluating the quality of my code and what parts need attention.

If you’re using NDepend for personal and non-commercial reasons, you can download it for free. It doesn’t have all the features, but it has more than enough. Professional use does require a license.

One of the things I was particularly impressed with was the amount of help content available. There are tons of tutorials for every part of the program.

I’m going to keep playing with this and I’m sure I’ll mention some more things as I discover them. For now, NDepend is very cool—it’s actually fun to play with, and it gives you good information for what to work on.

Links:

Google Chrome – the Good, Meh, Ugly, and This Means War

I just read all about Google Chrome, their new open-source browser, in the comic they put out. No download link at this time, but I’m sure it’s coming. My initial thoughts:

The Good

  • The JavaScript changes seems to make sense. The better garbage collector and speed improvements can’t hurt.
  • The free API to download lists of malware or phishing sites is pretty nice.

The Meh

  • UI changes. Making each tab its own browser entity and putting controls in each tab? That’s it? So what!
  • Some of the search enhancements are interesting, but I don’t think that anyone will care that much in the end.
  • Showing most popular pages…meh
  • Unclear on the plugin model. Will they have their own? Will they run ActiveX (they imply yes). How about Firefox plugin compatibility? All we need is yet another API for writing plugins.

The Ugly

  • A new process for each tab? Are you serious? I understand that it’s (maybe)the only way to completely isolate web pages from each other, but given how many pages some people have running, that means an extra 50 processes on the system. That’s a lot of resources. I know their idea was to consider each web page an application, and of course each desktop application is its own process, but I don’t think we actually treat most web pages like applications. We create new browser tabs and switch pages with wild abandon. Most web sites are NOT applications–they’re reference. They’re just books open to 50 pages at once. (Was process isolation really a problem that needed solving? I almost NEVER have runaway tabs in IE7)
  • Proprietary JavaScript hooks. Sure, it’s open source, but they’re still building things into their version of JavaScript that only work with their browser.

This Means War

  • First front: SilverLight. Gears seems to be a direct assault on the concept of .Net and SilverLight. The technology and scope are different now, but I think ultimately they’re going after the same target: having the rich-client experience in your browser on multiple OSes/browsers.
  • Second front: Firefox: the only people who are going to download Chrome or even understand what it is are the people who use Firefox. If Chrome succeeds, it will be at Firefox’s detriment. Thanks for playing.

Overall, I felt a big “meh” after reading the comic. While many of the ideas are interesting, overall, I don’t see a compelling reason to switch. I’ll try it out when it becomes available, and my opinions will probably change on some things, but Google is going to have to do a lot more to overthrow IE. Maybe their purpose really is to just throw ideas out there and see what sticks, what gets integrated into competing products, etc. We’ll just have to see what happens next. It’s going to be a fun couple of years!

(P.S. Also, please everyone, especially media, start mocking Chrome for it’s “p%%n mode” just liked you mocked IE.)