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
reflow/repaint
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Yuta Hiroto
November 10, 2016
Technology
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
reflow/repaint
11/11の社内勉強会資料
Yuta Hiroto
November 10, 2016
More Decks by Yuta Hiroto
See All by Yuta Hiroto
Node8.3.0について
abouthiroppy
1
3.2k
ECMAScript
abouthiroppy
0
700
my tools
abouthiroppy
0
160
OSSを楽しむ話
abouthiroppy
0
190
React Nativeを触ってみた話
abouthiroppy
0
180
Other Decks in Technology
See All in Technology
End-to-Endで考える信頼性 —LINEアプリにおけるクライアント開発×SRE連携の実践
maruloop
0
100
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
480
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
180
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
0
130
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
product engineering with qa
nealle
0
140
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
300
認証認可だけじゃない! ID管理の構成要素と ライフサイクルを意識しよう
ritou
1
460
【FinOps】データドリブンな意思決定を目指して
z63d
3
600
はてなのサービス基盤を支える Kubernetes《足腰》
masayoshimaezawa
0
430
NDIAS CTF 2026 問題解説会資料
bata_24
0
170
攻撃者がいなくてもAIエージェントはインシデントを起こす
nomizone
0
190
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
380
Between Models and Reality
mayunak
4
360
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
A designer walks into a library…
pauljervisheath
211
24k
Side Projects
sachag
455
43k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
220
The Mindset for Success: Future Career Progression
greggifford
PRO
0
370
Scaling GitHub
holman
464
140k
We Are The Robots
honzajavorek
0
260
Building Applications with DynamoDB
mza
96
7.1k
Facilitating Awesome Meetings
lara
57
7k
Transcript
Reflow / Repaint Yuta Hiroto @about_hiroppy #frontier-js-2
Reflow / Repaint ؾʹ͔͚ͯ·͔͢ʁ
ͳͥؾʹ͢Δඞཁ͋Δͷʁ ෛՙ͕େ͖͘ɺύϑΥʔϚϯεʹ Өڹ͕͋Δ͔Β UXͷԼ
ϒϥβͷඳըϓϩηε DOM Tree Style Rules HTML CSS Render Tree Layout
Paint Display Webkitͷ؆ུϑϩʔ
ϒϥβͷඳըϓϩηε DOM Tree Style Rules HTML CSS Render Tree Display
Layout ࠓ͢ͷ͜͜ Paint
Layout(Reflow) • GekkoͰReflow, WebkitͰLayoutͱݺΕ·͢ • ϨϯμʔπϦʔ͕࠶ධՁ͞Ε࠶ܭࢉ͢ΔॴͰ͢ • ཁૉʹḪͬͯ࠶ܭࢉ͢ΔͨΊɺύϑΥʔϚϯεʹ Өڹ͕ग़͍͢ ࠓճReflowͱݺͼਐΊ·͢
Paint • LayoutΑΓ͍͕ɺΓෛՙ͕ߴ͍ • Repaintͱ࠶ܭࢉ͞ΕͨϨϯμʔπϦʔͷ݁ՌΛݩʹ εΫϦʔϯΛߋ৽͢Δ͜ͱΛݴ͍·͢ • GPUϨϯμϦϯάΛ͏͜ͱʹΑΓɺൃੜΛ͑Δ͜ͱ͕Մೳ ΞχϝʔγϣϯͰtransform, opacityͳͲΛ༻͢Δ
• ҎԼͷϓϩύςΟ͕ओʹෛՙ͕ߴ͍ྫͰ͢ - box-shadow - border-radius - background - filter: blur - gradient - position:fixed
Reflow / Repaint Reflow Repaint ϨϯμʔπϦʔ͕࣋ͭ DOMཁૉΛ࠶ܭࢉ͢Δ εΫϦʔϯͷ ࠶ඳըॲཧΛ͢Δ
ൃੜτϦΨʔ ReFlow + RePaint RePaintͷΈ DOM NodeͷՃɾߋ৽ɾআ windowͷαΠζมߋɾεΫϩʔϧ ϑΥϯταΠζͷมߋ Ξχϝʔγϣϯ
ελΠϧଐੑͷՃɾมߋɾআ ίϯςΩετͷมߋ offsetWidth, offsetHeightͷ࠶ܭࢉ cssٖࣅΫϥεͷૢ࡞ css#color css#outline css#visibility: hidden css#backgroundColor
const style = document.body.style; // reflow + repaint style.border =
'1px solid #333'; style.padding = '10px'; style.fontSize = '1px'; document.body.appendChild(document.createTextNode('hoge!')); // repaint style.color = 'blue'; style.backgroundColor = '#0ff';
ൃੜΛ࠷খݶʹ͑Δ • styleͰͷมߋΛආ͚Δ • documentFragmentΛ͏
styleͰͷมߋΛආ͚Δ • DOMͷมߋճΛ1ճʹ ·ͱΊΔ • display: noneͰӅ͠มߋ(n ճ)ͤ͞displayΛ͢ (nճ ͷreflow/repaintʹର͠ɺ
͜ͷํ๏ͩͱ2ճͰࡁΉ) // js const el = document.body; const style = el.style; // bad style.left = '10px'; // reflow, repaint style.top = '20px'; // reflow, repaint // good el.classList.add("anotherclass"); // reflow, repaint // .css .anotherclass { left: 10px; top: 20px; }
ϒϥβͷΈ • ReFlow/RePaintෛՙ͕ߴ͍ͨΊɺ ϒϥβࣗମ͕࠷దԽΛߦ͍·͢ • ϒϥβJavaScript͔ΒͷstyleมߋΛΩϡʔʹ٧Ίɺ·ͱΊͯ ࠷ޙʹॲཧΛߦ͏͜ͱʹΑΓReflow/RepaintΛ࠷খݶʹ͑·͢ function updateBodyStyle() {
const style = document.body.style; style.top = '50px'; style.left = '30px'; style.right = '40px'; style.bottom = '20px'; } 4ճมߋΛߦ͍ͬͯΔ͕ Reflow/Repaint1ճ͔͠ൃੜ͠ͳ͍
ReFlowͷ࠷దԽΛյ͢ • ϒϥβstyleΛΩϡʔʹ٧ΊɺҰఆ࣌ؒܦ͔ͭมߋճͰΩϡʔΛ ϑϥογϡ͠·͢ • ҎԼͷελΠϧΛಡΈࠐΉͱڧ੍తʹϑϥογϡ͢Δ͜ͱ͕ՄೳͰ͢ - offsetTop/Left/Width/Height - scrollTop/Left/Width/Height
- clientTop/Left/Width/Height - getComputedStyle() - getClientRect() - scrollBy(), scrollTo() - scrollX, scrollY - height, width const div = document.querySelector('div'); for (let i = 0; i < 100; i++) { div.style.left = div.offsetLeft + 50 + 'px'; } ѱ͍ྫ ϧʔϓ֎ͰΩϟογϡ͢Δ͖
documentFragmentΛ͏ • documentFragmentΛ͍ɺෳͷมߋΛ ·ͱΊϨϯμʔπϦʔʹՃ͢Δ͜ͱʹΑΓ ReflowΛҰճʹ͑·͢ https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
chromeͰ֬ೝ͢Δํ๏ Rendering Timeline/Paint Profiler
·ͱΊ • ReFlowͱRePaintͷଟൃΛؾʹ͢ΔΑ͏ʹ͠Α͏ • ൃੜτϦΨʔʹͳΔJavaScriptʹؾΛ͚ͭΑ͏ • ΞχϝʔγϣϯCSS transformΛ͓͏
ࢀߟจݙ • https://www.html5rocks.com/ja/tutorials/ internals/howbrowserswork/ • http://rochas.cc/blog/2013/12/09/ frontrend.html • https://gist.github.com/paulirish/ 5d52fb081b3570c81e3a