What are potential performance issues when using BCL collections?
The most common performance problems with using BCL collections include: Boxing and unboxing overhead for valuetypes. All standard BCL collections will box a valuetype when it’s added to collection, and unbox it when retrieving the value from the collection. Using iterators (the foreach statement) may be expensive, as it unrolls into a sequence of virtual calls through the IEnumerator interface (GetEnumerator(), get_Current(), and MoveNext()). For example foreach statement in the following benign piece of code: ArrayList al = new ArrayList(str_array); foreach (String s in al) { //do something } is compiled into: IL_002b: callvirt instance class [mscorlib]System.Collections.IEnumerator [mscorlib]System.Collections.ArrayList::GetEnumerator() IL_0030: stloc.s CS$5$0001 .try { IL_0032: br.s IL_004a IL_0034: ldloc.s CS$5$0001 IL_0036: callvirt instance object [mscorlib]System.Collections.IEnumerator::get_Current() IL_003b: castclass [mscorlib]System.String … IL_004a: ldloc.s CS$5$0001 IL_
Related Questions
- Are sample collections anticipated to coincide with water withdrawals or are these potential sites for water withdrawal?
- What is the current and potential contribution of the aviation sector to the economic performance of Madrid Region?
- What are potential performance issues when using BCL collections?