Web Application Performance Design Inspection Questions - Data Structures and Algorithms

From Guidance Share

Jump to: navigation, search

- J.D. Meier, Srinath Vasireddy, Ashish Babbar, Rico Mariani, and Alex Mackman


Data Structure and Algorithm Issues



Choosing a collection without evaluating your needs (size, adding, deleting, updating)

Reduced efficiency; overly complex code.

Using the wrong collection for a given task

Reduced efficiency; overly complex code.

Excessive type conversion

Passing value type to reference type causing boxing and unboxing overhead, causing performance hit.

Inefficient lookups

Complete scan of all the content in the data structure, resulting in slow performance.

Not measuring the cost of your data structures or algorithms in your actual scenarios

Undetected bottlenecks due to inefficient code.

Consider the following questions to assess your data structure and algorithm design:

Do you use appropriate data structures? Do you need custom collections? Do you need to extend IEnumerable for your custom collections?

Do You Use Appropriate Data Structures?

Choosing the wrong data structure for your task can hurt performance because specific data structures are designed and optimized for particular tasks. For example, if you need to store and pass value types across a physical boundary, rather than using a collection, you can use a simple array, which avoids the boxing overhead.

Clearly define your requirements for a data structure before choosing one. For example, do you need to sort data, search for data, or access elements by index?

More Information

For more information about choosing the appropriate data structure, see .NET 2.0 Performance Guidelines - Collections and "Selecting a Collection Class" in the .NET Framework Developer's Guide on MSDN at http://msdn.microsoft.com/library/en-us/cpguide/html/cpconselectingcollectionclass.asp.

Do You Need Custom Collections?

For most scenarios, the collections provided by .NET Framework are sufficient, although on occasion, you might need to develop a custom collection. Carefully investigate the supplied collection classes before developing your own. The main reasons for wanting to develop your own custom collection include the following:

  • You need to marshal a collection by reference rather than by value, which is the default behavior of collections provided by .NET Framework.
  • You need a strongly typed collection.
  • You need to customize the serialization behavior of a collection.
  • You need to optimize on the cost of enumeration.

Do You Need to Extend IEnumerable for Your Custom Collections?

If you are developing a custom collection and need to frequently enumerate through the collection, you should extend the IEnumerable interface to minimize the cost of enumeration.

For more information, see Explained: Collections Explained

Personal tools