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 (Short Version)
Search
Ernesto Tagwerker
April 26, 2017
Technology
0
44
Micro Performance Improvements (Short Version)
Small Ruby and Rails code improvements you can do to have high performance in your application.
Ernesto Tagwerker
April 26, 2017
Tweet
Share
More Decks by Ernesto Tagwerker
See All by Ernesto Tagwerker
Stuck in the Tar Pit at Sin City Ruby '24
etagwerker
1
250
Lightning Talk: Escaping the Tar Pit
etagwerker
1
100
Fortify Rails Webinar
etagwerker
0
2.2k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
190
Lessons Learned from Open Source
etagwerker
0
79
Upgrading Rails: The Dual-Boot Way
etagwerker
1
460
Ruby 3.0 & Rails 6.1
etagwerker
0
170
RubyMem: The Leaky Gems Database for Bundler at Ruby Kaigi Takeout 2020
etagwerker
0
230
Escaping The Tar Pit at NYC.rb
etagwerker
0
93
Other Decks in Technology
See All in Technology
RSNA2024振り返り
nanachi
0
620
あれは良かった、あれは苦労したB2B2C型SaaSの新規開発におけるCloud Spanner
hirohito1108
2
770
PHPカンファレンス名古屋-テックリードの経験から学んだ設計の教訓
hayatokudou
2
510
EDRの検知の仕組みと検知回避について
chayakonanaika
2
530
人はなぜISUCONに夢中になるのか
kakehashi
PRO
6
1.7k
明日からできる!技術的負債の返済を加速するための実践ガイド~『ホットペッパービューティー』の事例をもとに~
recruitengineers
PRO
3
510
わたしのOSS活動
kazupon
2
300
一度 Expo の採用を断念したけど、 再度 Expo の導入を検討している話
ichiki1023
1
230
Visualize, Visualize, Visualize and rclone
tomoaki0705
9
67k
利用終了したドメイン名の最強終活〜観測環境を育てて、分析・供養している件〜 / The Ultimate End-of-Life Preparation for Discontinued Domain Names
nttcom
2
310
Helm , Kustomize に代わる !? 次世代 k8s パッケージマネージャー Glasskube 入門 / glasskube-entry
parupappa2929
0
270
Exadata Database Service on Cloud@Customer セキュリティ、ネットワーク、および管理について
oracle4engineer
PRO
1
1.5k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
137
6.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.6k
GraphQLとの向き合い方2022年版
quramy
44
13k
Producing Creativity
orderedlist
PRO
344
39k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.4k
Building Flexible Design Systems
yeseniaperezcruz
328
38k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.3k
GitHub's CSS Performance
jonrohan
1030
460k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
VelocityConf: Rendering Performance Case Studies
addyosmani
328
24k
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 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
# 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 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
https://github.com/ombulabs/benches/ 13
Resources 14
15 https://speakerdeck.com/etagwerker/micro- performance-improvements https://github.com/evanphx/benchmark-ips https://github.com/evanphx/benchmark.fyi
Thank you! @etagwerker 16