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
48
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
290
Lightning Talk: Escaping the Tar Pit
etagwerker
1
120
Fortify Rails Webinar
etagwerker
0
2.3k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
220
Lessons Learned from Open Source
etagwerker
0
94
Upgrading Rails: The Dual-Boot Way
etagwerker
1
470
Ruby 3.0 & Rails 6.1
etagwerker
0
190
RubyMem: The Leaky Gems Database for Bundler at Ruby Kaigi Takeout 2020
etagwerker
0
260
Escaping The Tar Pit at NYC.rb
etagwerker
0
110
Other Decks in Technology
See All in Technology
開発と脆弱性と脆弱性診断についての話
su3158
1
1.2k
モバイルアプリ研修
recruitengineers
PRO
4
1.2k
退屈なことはDevinにやらせよう〜〜Devin APIを使ったVisual Regression Testの自動追加〜
kawamataryo
4
870
AI時代に非連続な成長を実現するエンジニアリング戦略
sansantech
PRO
1
410
カミナシ社の『ID管理基盤』製品内製 - その意思決定背景と2年間の進化 #AWSUnicornDay / Kaminashi ID - The Big Whys
kaminashi
1
330
Devinを使ったモバイルアプリ開発 / Mobile app development with Devin
yanzm
0
210
Webアクセシビリティ入門
recruitengineers
PRO
3
1.2k
事業価値と Engineering
recruitengineers
PRO
6
4.3k
実践アプリケーション設計 ③ドメイン駆動設計
recruitengineers
PRO
11
2.7k
実践アプリケーション設計 ①データモデルとドメインモデル
recruitengineers
PRO
5
1.1k
帳票Vibe Coding
terurou
0
150
現場が抱える様々な問題は “組織設計上” の問題によって生じていることがある / Team-oriented Organization Design 20250827
mtx2s
6
50k
Featured
See All Featured
Facilitating Awesome Meetings
lara
55
6.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
15
1.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
1k
Making Projects Easy
brettharned
117
6.3k
The Cost Of JavaScript in 2023
addyosmani
53
8.8k
The Language of Interfaces
destraynor
160
25k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
284
13k
Why You Should Never Use an ORM
jnunemaker
PRO
59
9.5k
Making the Leap to Tech Lead
cromwellryan
134
9.5k
Art, The Web, and Tiny UX
lynnandtonic
302
21k
Raft: Consensus for Rubyists
vanstee
140
7.1k
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