Thursday, November 1, 2018

Pair With Me: Rubocop Detects Duplicate Array Allocations

You might know rubocop as the linter that helps enforce your code styles, but did you know you can use it to make your code faster? In this post, we'll look at static performance analysis and then at the end there's a video of me live coding a PR that introduces a new performance cop to rubocop.

Static Performance Analysis

Most performance improvements are made by "hotspot" analysis. You find some code and a benchmarking tool. Run the code, find the "hotspots" and then either speed up those sections or reduce the number of times that they need to be called. Concerning finding the most significant gains, nothing beats hotspot analysis, but what if you could detect code that is inefficient and re-write it without changing behavior. The code might be critical and the performance gain huge, or it might be tiny. Static performance analysis can tell you where your code can be faster, but it cannot tell you if that performance improvement will be meaningful in any kind of a real way.



from DZone.com Feed https://ift.tt/2Jwqfum

No comments:

Post a Comment