Closed remojansen closed 8 years ago
Why not a WeakMap or a Map itself?
@skyrpex thanks a lot this suggestion. Many times I made the mistake of forgetting that Map and WeakMaps are available. I though about using an AVL tree to improve complexity from O(n)
to O(log n)
. But looks like Map uses a hash table internally and achieves O(1) complexity. I will use a Map
:smile:
Expect this to be merged soon 🎉
That's impressive.
Nice!
Merged https://github.com/inversify/InversifyJS/pull/398 :tada:
Expected Behavior
I'm preparing some nice features and improvements for 3.0 and this is one of the things I though...
We can use a Map to replace the current implementation of binding dictionary insertion and search which are implemented with using an array. This would make the library much faster!
NOTE: No performance issues has been reported by users to this date I'm just being pro-active and improving things.
Current Behavior
At the moment the binding dictionary is an array. This array contains
KeyValuePair<T>
the key is aServiceIdentifier
and the value isT
.The current implementation has a
O(n)
complexity:This means that as we declare more and more dependencies the library gets slower and slower. Using a Map we will reach
O(1) complexity
Possible Solution
Use a Map instead of an array.
Steps to Reproduce (for bugs)
The
avl-dictionary
branch contains unit test that allow the performance validation:At the moment (before Map refactor) the test fail:
We need to find realistic times to prevent random build failures.