Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Micro Performance Improvements
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ernesto Tagwerker
April 26, 2017
Technology
70
0
Share
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
34
Teaching Code How To Upgrade Rails at Philly.rb
etagwerker
0
17
Teaching Claude Code to Upgrade Rails (Artificial Ruby NYC, March, 2026)
etagwerker
0
32
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
330
Lightning Talk: Escaping the Tar Pit
etagwerker
1
160
Fortify Rails Webinar
etagwerker
0
2.6k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
290
Lessons Learned from Open Source
etagwerker
0
130
Upgrading Rails: The Dual-Boot Way
etagwerker
1
500
Other Decks in Technology
See All in Technology
R&D 祭 2024 アニメエフェクト作成の効率化
olmdrd
PRO
0
100
LookerとADKで作る社内AIエージェント
chanyou0311
0
270
"うちにはまだ早い"は本当? ─ 小さく始めるPlatform Engineering入門
harukasakihara
7
640
既存プロダクトQAから新規プロダクトQAへ
ryotakahashi
0
160
AI Agent に“攻略本”を渡したら、150フォームの移行が回り始めた話/登壇資料(高橋 悟生)
hacobu
PRO
0
130
最新技術を"今は選ばない"という技術選定
leveragestech
PRO
0
260
20260515 ID管理は会社を守る大切な砦!〜🔰情シス向け〜
oidfj
0
710
Purview Endpoint DLP 動かしてみた
kozakigh
1
450
PdM・Eng・QAで進めるAI駆動開発の現在地/aidd-with-pdm-eng-qa
shota_kusaba
0
260
20260515 OpenIDファウンデーション・ジャパンご紹介
oidfj
0
220
クラウドネイティブ DB はいかにして制約を 克服したか? 〜進化歴史から紐解く、スケーラブルアーキテクチャ設計指針〜
hacomono
PRO
6
1.1k
障害対応のRunbookは作った、でも本当に動くの? AWS FIS で EKS の AZ 障害を再現してみた
tk3fftk
0
110
Featured
See All Featured
Claude Code のすすめ
schroneko
67
220k
We Are The Robots
honzajavorek
0
230
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Building an army of robots
kneath
306
46k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
180
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
Bash Introduction
62gerente
615
210k
Typedesign – Prime Four
hannesfritz
42
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9k
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