In ZclDataType, the use of Linq and Single results in enumerating the complete Dictionary each time the Get(DataType type) function is called. This has a serious performance impact as this function is called a lot from cluster classes (see first line of benchmark below).
First step was thus to refactor the function to effectively use the Dictionary (around 150x improvement).
Then I had the intuition that a Dictionary wasn't the most efficient way to implement that function. So I made some performance and memory benchmarks to check 3 alternatives to Dictionary: a class derived from KeyedCollection, an Array[16][16] that contains only no empty rows and a simple Array[256], the first giving a small memory advantage.
After analysis it appears that using a simple Array[256] is really giving a performance advantage and that the memory cost of that approach is lower than the Dictionary, even if this can be counter-intuitive at first glance. So I changed the class to use the simple array approach.
I also changed the ZigBeeProfileType to a pure Enum approach which is sufficient for that class.
Benchmark results
In the tables below : Get -> original Get function, Dict -> using the Dictionary, KeyedValue -> using a KeyedCollection, *SquareArray -> using Array[16][16], Array -> using Array[256]
In
ZclDataType
, the use ofLinq
andSingle
results in enumerating the completeDictionary
each time theGet(DataType type)
function is called. This has a serious performance impact as this function is called a lot from cluster classes (see first line of benchmark below).First step was thus to refactor the function to effectively use the
Dictionary
(around 150x improvement).Then I had the intuition that a
Dictionary
wasn't the most efficient way to implement that function. So I made some performance and memory benchmarks to check 3 alternatives to Dictionary: a class derived fromKeyedCollection
, anArray[16][16]
that contains only no empty rows and a simpleArray[256]
, the first giving a small memory advantage.After analysis it appears that using a simple
Array[256]
is really giving a performance advantage and that the memory cost of that approach is lower than theDictionary
, even if this can be counter-intuitive at first glance. So I changed the class to use the simple array approach.I also changed the
ZigBeeProfileType
to a pureEnum
approach which is sufficient for that class.Benchmark results
In the tables below : Get -> original Get function, Dict -> using the Dictionary, KeyedValue -> using a KeyedCollection, *SquareArray -> using Array[16][16], Array -> using Array[256]