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
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
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
遅い処理を速くするためのティップス集
Search
furuhashin
November 15, 2022
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
遅い処理を速くするためのティップス集
furuhashin
November 15, 2022
More Decks by furuhashin
See All by furuhashin
what changed when my position changed
furuhashin
0
230
Split a huge class
furuhashin
0
170
Obsidian is good
furuhashin
0
480
密かにバグ管理簿というものを作っている話
furuhashin
0
250
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
174
15k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
520
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
350
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Building Adaptive Systems
keathley
44
3.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
510
Done Done
chrislema
186
16k
Mobile First: as difficult as doing things right
swwweet
225
10k
Transcript
遅い処理を速くするためのティップス集 Nobukatsu Furuhashi
自己紹介 • @furuhashin • 趣味 • 実生
① N+1回のクエリは排除しよう • 全ての会社をとってきてから、その会社1件ごとに全社員を取得するクエリを発 行するようなやつ
① 解決策 • JOINをして一気にデータを取得する • 全ての会社数が多くない場合は全ての会社のidを取得して社員テーブルでwhere in 句を発行するでもおk • 会社のidが多すぎるとインデックスが効かなくなるので注意
①‘ N+1回の処理も排除しよう • 全ての会社をとってきてから、その会社1件ごとに全社員の画像をファイルサー バから取得する等
①’ 解決策 • まとめて取得する • 取得を遅延させる • URLだけ生成しておいて取得はブラウザでやってもらう等
②クエリを発行する際にインデックスを正しく使用 しよう • EXPLAINで都度確認する癖をつける • 第一候補はwhere句。他にはテーブル結合における条件キーやorder by句のソートキーと なっているカラム
③ループを少なくしよう • 先にループする対象を削減できないか検討する • 同じ配列に対して複数回ループ処理をしていたら1つにまとめる(ループの個数 削減)
④配列の値を検索しないようにしよう • In_array()等 • 検索される側が少ない場合は問題ない
④解決策 • キーで検索できるようにデータを作成しておく • [’apple’ => true]みたいな
⑤キャッシュしよう • マスター系のデータはほぼ変わることがないので、そのデータへのアクセス数が 大量にある場合はキャッシュするといい
⑥インスタンス変数を活用しよう • バッチ処理等での大量のループ処理の中で毎回キャッシュにアクセスする必要は ない
⑦仕様を見直そう • 毎回全件取得しているのはなぜ?前回との差分で良いのではないか?等