- username: pick the username shape (first-name-only vs first+last)
before generating names, so the discarded variant is never built.
- password: reuse frozen digit/special-char tables and grow the
character bag in place with concat instead of += (which copies the
whole array each time).
- base64: reuse frozen urlsafe/standard character tables and append
into a pre-sized String instead of building an intermediate array.
- sanitize_email_local_part: replace invalid characters with a single
gsub against a character-class regex instead of rebuilding the
allowed-character array and scanning it per character.
Benchmark (Ruby 3.4.9, arm64-darwin25, benchmark-ips):
require 'benchmark/ips'
require 'faker'
Benchmark.ips do |x|
x.config(warmup: 1, time: 2)
x.report('username') { Faker::Internet.username }
x.report('email') { Faker::Internet.email }
x.report('password') { Faker::Internet.password }
x.report('base64') { Faker::Internet.base64 }
end
Results:
main: username 41.048k (+/-14.7%) i/s
email 21.683k (+/- 0.7%) i/s
password 394.792k (+/- 4.8%) i/s
base64 183.509k (+/- 2.4%) i/s
this commit: username 79.313k (+/-18.2%) i/s (~1.9x)
email 37.246k (+/- 1.3%) i/s (~1.7x)
password 451.683k (+/- 1.0%) i/s (~1.14x)
base64 462.621k (+/- 0.5%) i/s (~2.5x)
Motivation / Background
This Pull Request has been created because I want to make these methods faster, because they're extremely common in the database seeds/tests of every Rails app I've ever worked on.
The changes in this PR were generated using Claude Code w/ Fable 5. They have been reviewed and tested by me for correctness.
Additional information
Benchmark (Ruby 3.4.9, arm64-darwin25, benchmark-ips):
Results:
main: username 41.048k (+/-14.7%) i/s email 21.683k (+/- 0.7%) i/s password 394.792k (+/- 4.8%) i/s base64 183.509k (+/- 2.4%) i/s this commit: username 79.313k (+/-18.2%) i/s (~1.9x) email 37.246k (+/- 1.3%) i/s (~1.7x) password 451.683k (+/- 1.0%) i/s (~1.14x) base64 462.621k (+/- 0.5%) i/s (~2.5x)Checklist
Before submitting the PR make sure the following are checked:
If you're proposing a new generator or locale: