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
Server Side Rendering Tuning with Next.js
Search
Yutaro Miyazaki
July 03, 2019
Technology
1.6k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Server Side Rendering Tuning with Next.js
Yutaro Miyazaki
July 03, 2019
More Decks by Yutaro Miyazaki
See All by Yutaro Miyazaki
React + Apollo Client (GraphQL) により変化するアプリケーション設計
vwxyutarooo
6
3.3k
The challenge of Mercari Web Re-Architecture Project
vwxyutarooo
1
190
ゼロから始めるっぽい Service Worker
vwxyutarooo
5
1.1k
Other Decks in Technology
See All in Technology
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
980
証券システムを10年Scalaで作り続けるということ - 関数型まつり2026
krrrr38
3
690
AI Driven AI Governance
pict3
0
150
プロダクトだけじゃない、社内プロセスにおける自動化・省力化ノススメ
kakehashi
PRO
1
890
組織における AI-DLC 実践
askul
0
320
ローカルLLMとLINE Botの組み合わせ その3 / LINE DC Generative AI Meetup #8
you
PRO
0
110
美しいコードを書くためにF#を学んでみた話
yud0uhu
1
230
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.3k
小さいから、全部わかる。— 常駐AI "xangi" のすすめ
sugupoko
0
270
CIで使うClaude
iwatatomoya
0
110
スタートアップにおけるアジャイルの実践について #shibuyagile
murabayashi
3
2.1k
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
510
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
How to Ace a Technical Interview
jacobian
281
24k
HDC tutorial
michielstock
2
730
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
67
56k
Everyday Curiosity
cassininazir
0
250
Navigating Weather and Climate Data
rabernat
0
280
Why Our Code Smells
bkeepers
PRO
340
58k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
The World Runs on Bad Software
bkeepers
PRO
72
12k
A Tale of Four Properties
chriscoyier
163
24k
First, design no harm
axbom
PRO
2
1.2k
Transcript
Server Side Rendering Tuning with Next.js Server Side Rendering Tuning
with Next.js Mercari x Merpay Frontend Tech Talk vol.2 @vwxyuratoooo
Yutaro Miyazaki (@vwxyutarooo) Yutaro Miyazaki (@vwxyutarooo) 2012~ Jobless 2013~ Freelance
2016~ Startup 2018~ Mercari
My Talk is About... My Talk is About... Our new
architecture of Mercari Web The performance issue of Server Side Rendering with Next.js
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
What Web Re-Architecture is What Web Re-Architecture is
Ancient Huge PHP Code ↓ Modern Architecture
None
None
None
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Apollo Apollo
None
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
None
Next.js Upside Next.js Upside Build System Smart Chunk System Various
Practices
Next.js Downside Next.js Downside Folder Structure Router We hit the
Server Side Rendering Performance issue...?
Server Side Rendering Performance?
None
100 requests per second. 40 CPU cores were waste. It
still doesn't reaches to 100 requests per second On the production environment It's supposed to spend 800 CPU cores.
None
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Performance Tuning Performance Tuning How can we solve this catastrophic
performance issue
Render method tuning renderToNodeStream for example. Cache
Investigation Investigation
What We Learned is What We Learned is Styled Components
CategoryLists component Contained regular expression. renderToStaticMarkup and renderToHTML .
Things we've adopted: Prevent HTML from rendering twice. Client Side
Render Component.
1. Prevent HTML From Rendered Twice 1. Prevent HTML From
Rendered Twice
Why Why It's rendered twice by renderToStaticMarkup and renderToHTML ?
None
The case of React Apollo const Dogs = ({ onDogSelected
}) => ( <Query query={GET_DOGS}> {({ loading, error, data }) => { if (loading) return 'Loading...'; if (error) return `Error! ${error.message}`; return ( <select name="dog" onChange={onDogSelected}> {data.dogs.map(dog => ( <option key={dog.id} value={dog.breed}> {dog.breed} </option> ))} </select> ); }} </Query> );
None
None
For general purpose, React Apollo needs to correct all queries
from component tree.
Our Solution Our Solution Fragments + React Apollo Fragments +
Apollo Client
Fragments: query GetPerson { people(id: "7") { firstName lastName avatar(size:
LARGE) } } fragment NameParts on Person { firstName lastName } query GetPerson { people(id: "7") { ...NameParts avatar(size: LARGE) } }
None
const data = (await apolloClientInstance.query(queryOptions)).data;
Measuring Performance (again) Measuring Performance (again)
None
2. Client Side Render Component 2. Client Side Render Component
None
None
By DynamicComponent: import dynamic from 'next/dynamic'; const DynamicComponentWithNoSSR = dynamic(
() => import('../components/hello3'), { ssr: false } ); export default const Index = () => <div><DynamicComponentWithNoSSR /></div>;
Measuring Performance (again) Measuring Performance (again)
Topics Topics Mercari Web Re-Architecture Apollo Next.js Performance Tuning Conclusion
Additionally The Latency Duration has Improved P50: 1,000ms -> 600ms
Also we saved nearly 1.5 million yen per month.
It doesn't matter which frame work you choose, the performance
needs to be considered by application.
Don't Guess, Measure.