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
52
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
310
Lightning Talk: Escaping the Tar Pit
etagwerker
1
140
Fortify Rails Webinar
etagwerker
0
2.4k
Here Be Dragons: The Hidden Gems of Technical Debt
etagwerker
0
260
Lessons Learned from Open Source
etagwerker
0
110
Upgrading Rails: The Dual-Boot Way
etagwerker
1
490
Ruby 3.0 & Rails 6.1
etagwerker
0
210
RubyMem: The Leaky Gems Database for Bundler at Ruby Kaigi Takeout 2020
etagwerker
0
270
Escaping The Tar Pit at NYC.rb
etagwerker
0
130
Other Decks in Technology
See All in Technology
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
230
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
120
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
190
広告の効果検証を題材にした因果推論の精度検証について
zozotech
PRO
0
170
GitHub Issue Templates + Coding Agentで簡単みんなでIaC/Easy IaC for Everyone with GitHub Issue Templates + Coding Agent
aeonpeople
1
220
プロポーザルに込める段取り八分
shoheimitani
1
240
MCPでつなぐElasticsearchとLLM - 深夜の障害対応を楽にしたい / Bridging Elasticsearch and LLMs with MCP
sashimimochi
0
170
Bill One急成長の舞台裏 開発組織が直面した失敗と教訓
sansantech
PRO
2
370
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
360
AI駆動PjMの理想像 と現在地 -実践例を添えて-
masahiro_okamura
1
110
Claude_CodeでSEOを最適化する_AI_Ops_Community_Vol.2__マーケティングx_AIはここまで進化した.pdf
riku_423
2
570
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
0
110
The Cult of Friendly URLs
andyhume
79
6.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.6k
Building Adaptive Systems
keathley
44
2.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
First, design no harm
axbom
PRO
2
1.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
290
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
66
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Google's AI Overviews - The New Search
badams
0
910
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