Skip to content

Conversation

divineforest
Copy link

No description provided.

@kuldeepaggarwal
Copy link
Contributor

There are so many other places, so please do it there also, if it is not a cosmetic change.

cc @rafaelfranca

@akshay-vishnoi
Copy link
Contributor

I think this is a cosmetic change.

@robin850
Copy link
Member

Hello @divineforest,

Thanks for the patch but we generally do not accept cosmetic patches (see here why). It could be accepted if there was a performance boost but it looks like .keys.each and .each_key are pretty similar regarding performances.

If I'm wrong, feel free to comment so we can reopen this. :-)

@robin850 robin850 closed this Sep 28, 2014
@divineforest
Copy link
Author

@robin850 the benefit is that each_key does not allocate objects and keys allocated new array

@sferik
Copy link
Contributor

sferik commented Sep 29, 2014

hash.keys.each allocates an array of keys; hash.each_key iterates through the keys, without allocating a new array. This is the reason why each_key exists.

@rafaelfranca
Copy link
Member

👍 for bulk change. So please update in all the places we use keys.each

@sferik
Copy link
Contributor

sferik commented Sep 29, 2014

@rafaelfranca @divineforest Bulk change added in #17099.

@robin850 The reason your benchmark does not show significant performance gains (and my does) is your hash is comprised of symbols, so calling keys only allocates one new object (the array). If the keys in a hash are strings, calling keys results in n + 1 allocations (where n is the number of keys).

@rafaelfranca
Copy link
Member

Closing in favor of #17099

@divineforest divineforest deleted the keys-each-optimize branch September 30, 2014 11:37
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

Successfully merging this pull request may close these issues.

6 participants