Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] why deleting value by object key is slow ? #4

Open
orangemi opened this issue Dec 25, 2016 · 5 comments
Open

[Question] why deleting value by object key is slow ? #4

orangemi opened this issue Dec 25, 2016 · 5 comments

Comments

@orangemi
Copy link

You mentioned in README.md:

Then I discovered why some of the fast algorithms where so slow - they used delete cache[key] which is much slower than cache[key] = value, much much slower.

Do you have any tip about why deleting value by object key is slow ? I'm just curious about the reason.

@wesleytodd
Copy link

AFAIK, JS uses hidden classes to optimize property lookup on objects with the same shape. Deleting a property makes the current hidden class invalid, so the VM has to use a much slower generic representation.

@ibigbug
Copy link

ibigbug commented Dec 26, 2016

@orangemi
Copy link
Author

@ibigbug nice!

@dominictarr
Copy link
Owner

reopening this issue because the linked article did not answer the question for me.
hashlru should certainly be putting things the cache into hash table mode. I can see that deleting from a hidden class object and changing to a hash table object would be expensive, but I don't know why deleting from a hash table is more expensive...

Hmm, it just occured to me that I am using incrementing integers as keys. maybe this is handled as a special case and is not a hash table? I'll have to do another bench mark to test.

@dominictarr dominictarr reopened this Dec 27, 2016
@Kikobeats
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants