C#C
C#2y ago
The Mist

✅ :white_check_mark: Dictionary<int, ...> lookup time seems a bit too slow

I was profiling a program, and I saw this:
100 % HasObject • 136 ms • 189 217 Calls • Engine.Runtime.Heap.HasObject(Int32)
    ↳ 50.3 % FindEntry • 68 ms • 189 217 calls • System.Collections.Generic.Dictionary`2.FindEntry(TKey)


Here is the code in question:
private Dictionary<int, RawObjectType> _objectId_object_map = new Dictionary<int, RawObjectType>();

public bool HasObject(int id)  
{  
    return _objectId_object_map.ContainsKey(id);  
}


136ms for 190,000 calls is translates to about 1,400 lookups per millisecond. That seems a little slow to me, is it not? If it is, why could this be? I figured looking up an int in a hashmap should be faster than that.
Was this page helpful?