Use Gem fasterer to speed up your Ruby code.

May 12, 2020

Overview

Using Fasterer, you can suggest speed improvements for your Ruby code. The proposal can be found at Fast Ruby.

Install

Gemfile
group :development do
  gem 'fasterer', require: false
end
$ bundle install

How to use

Inspection

$ bundle exec fasterer

Settings

Create .fastener.yml in the root directory of the project.

$ touch .fasterer.yml

Describe the settings. You can see the detailed settings at here.

.fasterer.yml
speedups:
  rescue_vs_respond_to: true
  module_eval: true
  shuffle_first_vs_sample: true
  for_loop_vs_each: true
  each_with_index_vs_while: false
  map_flatten_vs_flat_map: true
  reverse_each_vs_reverse_each: true
  select_first_vs_detect: true
  sort_vs_sort_by: true
  fetch_with_argument_vs_block: true
  keys_each_vs_each_key: true
  hash_merge_bang_vs_hash_brackets: true
  block_vs_symbol_to_proc: true
  proc_call_vs_yield: true
  gsub_vs_tr: true
  select_last_vs_reverse_detect: true
  getter_vs_attr_reader: true
  setter_vs_attr_writer: true

exclude_paths:
  - 'vendor/**/*.rb'
  - 'db/schema.rb'

Working with overcommit

By linking fasterer with overcommit, you can make sure that you don't forget to check fasterer. If you haven't installed overcommit, please refer to How to install Git Hooks (overcommit) so that you don't forget to run rubocop to install it.

Add the following configuration to .overcommit.yml. This will prevent you from committing if there is a warning in fasterer.

.overcommit.yml
PreCommit:
  Fasterer:
    enabled: true
    description: 'Analyzing for potential speed improvements'
    command: ['bundle', 'exec', 'fasterer']