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
reflow/repaint
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuta Hiroto
November 10, 2016
Technology
220
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.3k
ECMAScript
abouthiroppy
0
720
my tools
abouthiroppy
0
180
OSSを楽しむ話
abouthiroppy
0
210
React Nativeを触ってみた話
abouthiroppy
0
200
Other Decks in Technology
See All in Technology
Maestro MCPとClaude Code Skillsによる自律的なE2Eテスト支援
asmz
0
420
Sinatra on PicoRuby ローカルでセルフホスト
bash0c7
0
100
In-Context Learning再入門。ICLの勾配降下的解釈の研究動向を追ってみる。
dai08srhg
1
350
Don't write the architecture only in the prompt.
neohsu
0
310
企画からFlutter実装まで、1つの機能を一貫して開発したプロセスと成果物
khiroyuki1003
1
160
リアクションエンジニア ― 小さなリアクションから、話しかけやすい組織をつくる ―
ryuguyana
1
130
FinOpsを導入してマルチプロダクトのコスト最適化を実現する
kworkdev
PRO
0
130
re:Invent2026 事前勉強会 歴史と愉しみ方10分LT編
toshi_atsumi
0
140
2拠点SRE活動始めてみた | sogaoh's LT @ ホンマでっかSRE勉強会 #3
sogaoh
PRO
0
240
OneLakeをデータソースにした AI Search(Foundry IQ)の ライフサイクル管理
ryuseiiida
0
230
AI Agent 時代のデータ基盤: ClickHouse で実現する 超高速分析とコスト削減の両立
jozono
0
190
SLOを阻む不安
sraku2159
0
220
Featured
See All Featured
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.3k
Site-Speed That Sticks
csswizardry
13
1.6k
Typedesign – Prime Four
hannesfritz
42
3.2k
How GitHub (no longer) Works
holman
316
150k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
320
Navigating Team Friction
lara
192
16k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
290
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
760
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
470
Marketing to machines
jonoalderson
1
6k
Code Reviewing Like a Champion
maltzj
529
40k
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