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
7日分も開けないレポートが180日分返るまで - 計測と修正のサイクルで回すActiveRec...
Search
hirocy
October 29, 2026
Programming
51
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
7日分も開けないレポートが180日分返るまで - 計測と修正のサイクルで回すActiveRecordパフォーマンス改善
hirocy
October 29, 2026
More Decks by hirocy
See All by hirocy
connect-goとsqlboilerで構築するクリーンアーキテクチャ
hirocy
0
2k
Other Decks in Programming
See All in Programming
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
290
Zero-Tap Sign-In対応、結局何をすればいいの?
mitohato14
0
1.8k
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
140
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
300
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
160
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
330
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
210
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
330
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
180
AI-Powered Domain-Driven Design
ziobrando
0
410
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.6k
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.4k
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
570
Amusing Abliteration
ianozsvald
1
380
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
970
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
630
Darren the Foodie - Storyboard
khoart
PRO
4
4.1k
So, you think you're a good person
axbom
PRO
2
2.3k
A Tale of Four Properties
chriscoyier
163
24k
Crafting Experiences
bethany
1
430
A designer walks into a library…
pauljervisheath
211
25k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
48k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
470
Transcript
7日分も開けないレポートが 180日分返るまで 計測と修正のサイクルで回す ActiveRecord パフォーマンス改善 pixiv Inc. hirocy 2026.10.19
自己紹介 💼 23新卒/広告開発 ❤ Game/VTuber hirocy 広告なんでも Unit エンジニア https://x.com/hir0cy
pixiv Ads とは... 「pixiv」の運用型広告配信プラットフォーム https://ads.pixiv.net/lp 3
レポートは 3つのテーブルを集計する 広告主はレポートを見て、予算や配信を調整する 4 campaign_delivery_report_dailies # 日別の実績(過去日) delivery_report_hourlies # 時間別の実績(当日)
campaign_bills -> bills -> bill_months # 請求(消化金額)
7日分すら、レポートが開けない 「広告のレポートが 一切見られないのですが …」 5
計測と修正の サイクル を回す 6 スパンを見る 1 2 AI で逆引き もう一度計測
4 3 コードを直す
1リクエストで SQL が322クエリ発行されて いた 388 ms の SQL が1クエリ 7
短い SQL が244クエリ
Q1. どこが悪い? SELECT delivery_report_hourlies.* ... WHERE campaign_id IN (?) --
388 ms AI で発行元を探す campaigns_scope.includes(:delivery_report_hourlies, ...) 8
A1. 全期間を preload していた SELECT delivery_report_hourlies.* ... WHERE campaign_id IN
(?) -- report_at の条件が無い campaigns_scope.includes(:delivery_report_hourlies, ...) # includes は関連を丸ごと読む。N+1 対策で付けていた 1広告あたり 2,066行。使うのは当日の 15行だけ 9
修正1. 当日分だけ includes する # 当日分だけを読む関連 has_many :todays_delivery_report_hourlies, -> {
where(report_at: Time.current.all_day) } # 期間に今日を含むときだけ includes(:todays_delivery_report_hourlies) 時間別が必要なのは当日分だけ 10
Q2. どこが悪い? SELECT bills.* FROM bills WHERE bills.id = ?
LIMIT ? -- ×122 AI で発行元を探す fixed_bills = campaign_bills.joins(bill: :bill_month) fixed_bills.map { |cb| cb.bill.bill_month.month } 11
A2. joins は関連をロードしない fixed_bills = campaign_bills.joins(bill: :bill_month) # joins は
JOIN するだけ。bill はロードされない fixed_bills.map { |cb| cb.bill.bill_month.month } # 辿るたびに1件ずつ SELECT(bills、bill_months 各122回) joins を書いていても、 N+1 になる 12
修正2. 必要な2列だけ pluck する campaign_bills .joins(bill: :bill_month) .pluck('campaign_bills.price', 'bill_months.month') 1つの
SQL で、返したい値だけを取る 13
180日分まで返せるようになった 322 → 59 クエリ SQL のクエリ数 取得期間の上限 90日 →
180日 14
重いページもトレースをもとに直せる スパンを見る AI で逆引き コードを直す • includes は、範囲を絞らないと全件を読む • joins
は、関連をロードしない 15 もう一度計測