awesome-print / awesome_print

Pretty print your Ruby objects with style -- in full color and with proper indentation
http://github.com/michaeldv/awesome_print
MIT License
4.08k stars 454 forks source link

Additional performance tuning for Arrays #270

Closed dgynn closed 8 years ago

dgynn commented 8 years ago

This is a follow-on from the changes in #264 and fully eliminates the performance overhead on Arrays when not working with arrays of methods.

Using the same benchmark script as the previous PR will show the performance of any Array differencing is the same with or without awesome_print loaded. The timing for the benchmarks depends on the complexity of the arrays being tested. I'm seeing a ~35% overhead eliminated for the simplest case of [] - [].

# Initial results (on master)
Before IPS: 6672995.80047777
After IPS: 4935828.68755387
Speed difference: 1.3519504470048407
Before allocated: 40 bytes (1 objects)
After  allocated: 40 bytes (1 objects)
Memory difference: +0 bytes
Memory difference: +0 objects

# Results after converting Array extensions to AwesomeMethodArray module
Before IPS: 6601333.422140501
After IPS: 6840107.4153905865
Speed difference: 0.9650920696489602
Before allocated: 40 bytes (1 objects)
After  allocated: 40 bytes (1 objects)
Memory difference: +0 bytes
Memory difference: +0 objects

@michaeldv You have a old, old comment in code for "If you could think of a better way please let me know" so I thought you might want to check this out too.

gerrywastaken commented 8 years ago

@dgynn As small as this PR is, I'm pretty snowed under at the moment so won't have time to look into it, in detail, for a while. I just wanted you to know that the PR is hugely appreciated and I'll take a look as soon as I can.

dgynn commented 8 years ago

Thanks, @gerrywastaken. No rush at all.

gerrywastaken commented 8 years ago

@dgynn Finally got an afternoon free to look over this. Amazing work!