fasterer icon indicating copy to clipboard operation
fasterer copied to clipboard

Recommended fetch with block over args as faster

Open schneems opened this issue 9 years ago • 7 comments

From https://github.com/rails/rails/pull/26599 i'm seeing that's not the case. Btw, this is a really cool project.

cc/ @timrogers

schneems avatar Oct 04 '16 15:10 schneems

Thnx @schneems, I'll take a look at it, however I think I will have to make this project ruby-version specific since it seems that speed varies from version to version.

DamirSvrtan avatar Oct 23 '16 21:10 DamirSvrtan

FWIW, I just tried Ruby 1.9.3, 2.3.1, 2.3.3, and 2.4.0, and in all those versions, the argument version was faster than the block version.

monfresh avatar Jan 24 '17 03:01 monfresh

see this note on https://github.com/JuanitoFatas/fast-ruby#hashfetch-with-argument-vs-hashfetch--block-code it seems from that that we should make a distinction between a constant argument and method argument.

gagalago avatar Oct 12 '21 14:10 gagalago

@gagalago would you be open to creating a PR with a fix for this?

Best, Damir

DamirSvrtan avatar Oct 23 '21 02:10 DamirSvrtan

I can check but I will not do any promise. I am not familiar with code of fasterer (neither from other linters) so I don't know if I will be able to do it.

gagalago avatar Oct 25 '21 15:10 gagalago

Sure thing! Lemme know if you need any help figuring anything around the codebase, probably a good start would be checking this method over here: https://github.com/DamirSvrtan/fasterer/blob/master/lib/fasterer/scanners/method_call_scanner.rb#L116

DamirSvrtan avatar Oct 25 '21 17:10 DamirSvrtan

Hey guys, if you don't mind I created a small PR with the fix https://github.com/DamirSvrtan/fasterer/pull/93 Please check it when you have time, probably did something wrong...

connicov1 avatar Nov 03 '21 17:11 connicov1