Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Micro Performance Improvements
Search
Ernesto Tagwerker
April 26, 2017
Technology
86
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Micro Performance Improvements
A few changes that you can do to your code to make it have a faster performance
Ernesto Tagwerker
April 26, 2017
More Decks by Ernesto Tagwerker
See All by Ernesto Tagwerker
Teaching Claude Code to Upgrade Rails at Blue Ridge Ruby '26
etagwerker
0
75
Teaching Code How To Upgrade Rails at Philly.rb
etagwerker
0
42
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
71
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
350
Lightning Talk: Escaping the Tar Pit
etagwerker
1
180
Fortify Rails Webinar
etagwerker
0
2.7k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
320
Lessons Learned from Open Source
etagwerker
0
140
Upgrading Rails: The Dual-Boot Way
etagwerker
1
510
Other Decks in Technology
See All in Technology
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
610
20260906 「AWS運用入門」著者が教える、運用業務への生成AI活用入門
masaruogura
0
250
振り返りこそエンジニアの本領
negima
0
350
Claude Code本って、 読む必要あるの?
oikon48
1
290
Adaptive Warehouse を今すぐ導入すべき理由と迷ったときの判断基準
__allllllllez__
0
130
10分で知る最近のOmarchy
komagata
0
180
Where Is JetBrains AI Heading- — Central CLI, Air Alpha, and the Agentic Development Stack
x5gtrn
PRO
0
150
ペアプロの価値はコードを書くことだけじゃない
codmoninc
PRO
0
150
DEFCON34-Write-up_HYCu-MYCu
daikiokazaki
0
110
薬剤師(ドメインエキスパート)と一緒に育てる薬局向けAIアシスタント
kakehashi
PRO
2
130
推論の観測、できていますか? 〜 Google Cloud Gemini Enterprise Agent Platformで 3つの Gemini モデルを実測して踏んだ、評価の罠 〜
shukob
PRO
0
180
ASTを使って影響範囲を特定する
nealle
0
130
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
So, you think you're a good person
axbom
PRO
2
2.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2.2k
Raft: Consensus for Rubyists
vanstee
141
7.7k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
680
Joys of Absence: A Defence of Solitary Play
codingconduct
1
490
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Design in an AI World
tapps
1
310
Paper Plane (Part 1)
katiecoart
PRO
1
11k
Designing for Performance
lara
611
70k
Transcript
Micro Performance Improvements RailsConf, April 2017
Ernesto Tagwerker @etagwerker Founder & Software Developer at Ombu Labs
Best Practices 3
https://github.com/bbatsov/ruby-style-guide
https://speakerdeck.com/sferik/writing-fast-ruby
Bad Code vs. Good Code 6
# Bad return true unless OBJECT.nil? # Good return true
if OBJECT
Benchmark.ips do |x| OBJECT = "nil".freeze x.report("unless nil") do true
unless OBJECT.nil? end x.report("if object") do true if OBJECT end x.compare! end
$ bundle exec ruby benchmarks/unless_nil_vs_if_object.rb Ruby version: 2.3.3 Warming up
-------------------------------------- unless nil 251.994k i/100ms if object 267.552k i/100ms Calculating ------------------------------------- unless nil 9.435M (± 6.9%) i/s - 47.123M in 5.021124s if object 11.431M (± 4.9%) i/s - 57.256M in 5.021363s Comparison: if object: 11431148.2 i/s unless nil: 9435226.8 i/s - 1.21x slower
# OK phone = Hash.new(number: number) phone[:number] # Better Phone
= Struct.new(:number) phone = Phone.new(number) phone.number
$ bundle exec ruby benchmarks/struct_vs_hash.rb Ruby version: 2.3.3 Warming up
-------------------------------------- struct 22.148k i/100ms hash 4.688k i/100ms Calculating ------------------------------------- struct 240.460k (± 2.7%) i/s - 1.218M in 5.069592s hash 47.926k (± 3.9%) i/s - 243.776k in 5.094413s Comparison: struct: 240459.9 i/s hash: 47926.1 i/s - 5.02x slower
# Bad HOUR_6 = Time.parse("2000-01-01 06:00:00 UTC") # Good HOUR_6
= Time.at(946685160).utc
$ bundle exec ruby benchmarks/time/parse_vs_at.rb Ruby version: 2.3.3 Warming up
-------------------------------------- Time.parse 3.287k i/100ms Time.at 66.086k i/100ms Calculating ------------------------------------- Time.parse 34.052k (± 3.2%) i/s - 170.924k in 5.024737s Time.at 842.576k (± 2.2%) i/s - 4.230M in 5.022207s Comparison: Time.at: 842576.2 i/s Time.parse: 34051.9 i/s - 24.74x slower
# Bad Post.select(:id).map(&:id) # Good Post.pluck(:id)
$ bundle exec rake benches:pluck_vs_map Ruby version: 2.3.3 Warming up
-------------------------------------- map(&:id) 11.000 i/100ms pluck(:id) 80.000 i/100ms Calculating ------------------------------------- map(&:id) 124.205 (±11.3%) i/s - 616.000 in 5.026999s pluck(:id) 807.127 (± 2.0%) i/s - 4.080k in 5.057062s Comparison: pluck(:id): 807.1 i/s map(&:id): 124.2 i/s - 6.50x slower
Resources 16
17 https://github.com/ombulabs/benches/ https://github.com/evanphx/benchmark-ips https://github.com/evanphx/benchmark.fyi
Thank you! @etagwerker 18