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
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Agile that works and the tools we love
rasmusluckow
331
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
53
4k
SEO for Brand Visibility & Recognition
aleyda
0
4.8k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
830
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Discover your Explorer Soul
emna__ayadi
2
1.3k
Six Lessons from altMBA
skipperchong
29
4.5k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
550
Optimizing for Happiness
mojombo
378
71k
Building an army of robots
kneath
307
47k
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]みたいな
⑤キャッシュしよう • マスター系のデータはほぼ変わることがないので、そのデータへのアクセス数が 大量にある場合はキャッシュするといい
⑥インスタンス変数を活用しよう • バッチ処理等での大量のループ処理の中で毎回キャッシュにアクセスする必要は ない
⑦仕様を見直そう • 毎回全件取得しているのはなぜ?前回との差分で良いのではないか?等