{} is a dictionary by itself. Calculating the size by Object.keys().length is a very not performant and bad idea..since you are implementing a map, you need to keep a count in the state and increase it when setting and decrease it when deleting
I am a software Developer, experienced in both front and back-end development, proficient in HTML5, CSS3, SASS, JavaScript, Reactjs, Nodejs, Expressjs and Mongodb etc.
Ok thanks for this. I will give it a shoot. But why do you think maintaining the length in the state has better performance than calling the length property directly on the object.keys?
so object.keys will do a loop so we are talking about O(n) complexity while maintaining a count is O(1). So if we have 10000 elements in the map that is starting to be expensive. Also the map should be iterrable, I guess yours isnt yet :)
I am a software Developer, experienced in both front and back-end development, proficient in HTML5, CSS3, SASS, JavaScript, Reactjs, Nodejs, Expressjs and Mongodb etc.
{} is a dictionary by itself. Calculating the size by Object.keys().length is a very not performant and bad idea..since you are implementing a map, you need to keep a count in the state and increase it when setting and decrease it when deleting
Ok thanks for this. I will give it a shoot. But why do you think maintaining the length in the state has better performance than calling the length property directly on the object.keys?
Any tips on how you measure it?
so object.keys will do a loop so we are talking about O(n) complexity while maintaining a count is O(1). So if we have 10000 elements in the map that is starting to be expensive. Also the map should be iterrable, I guess yours isnt yet :)
Thanks!