tl; drïŒã³ãŒãã®åæž=解æ/ã³ã³ãã€ã«ã®åæž+転éã®åæž+解åã®åæž
ãããã¯ãŒã¯
ã»ãšãã©ã®éçºè ã¯ãJavaScriptã®ã³ã¹ãã«ã€ããŠèãããšããããŠã³ããŒãæéãšå®è¡æéã«ã€ããŠèããŸãã ããå€ãã®JavaScriptãã€ããéä¿¡ããã«ã¯æéããããããŠãŒã¶ãŒãšã®ãã£ãã«ãèããªããŸãã
ãŠãŒã¶ãŒã®å¹æçãªãããã¯ãŒã¯æ¥ç¶ã®ã¿ã€ãã¯å¿ ããã3Gã4GããŸãã¯WiFiã§ã¯ãªããããããã¯æåã®äžçã®åœã§ãåé¡ã«ãªãå¯èœæ§ããããŸã ã WiFiãåããã«ãã§ã«åº§ã£ãŠãã2Gã®é床ã§æºåž¯é»è©±ãä»ããŠãããã¹ãããã«æ¥ç¶ã§ããŸãã
JavaScriptãããã¯ãŒã¯ã®äŒéã³ã¹ãã¯ã次ã®æ¹æ³ã§åæžã§ããŸãã
- ãŠãŒã¶ãŒãå¿ èŠãšããã³ãŒãã®ã¿ãæž¡ããŸã ã ããã§ã³ãŒããéšåã«åå²ãããšåœ¹ç«ã¡ãŸãã
- ãããã£ã±ãŒã·ã§ã³ ïŒES5ã®å Žåã¯Uglifyã ES2015ã®å Žåã¯babel-minifyãŸãã¯uglify-es ïŒã
- æ倧å§çž® ïŒ Brotliãq11 ãZopfliãŸãã¯gzipã䜿çšïŒã Brotliã¯ãå§çž®ã«ãããŠgzipãããåªããŠããŸãã CertSimpleã§ã¯ãJSã³ãŒãã17ïŒ åæžããLinkedInã¯ããŒãæéã4ïŒ åæžããŸãã ã
- æªäœ¿çšã®ã³ãŒããåé€ããŸã ã DevToolsã®ã³ãŒãã«ãã¬ããžããŒã«ã§èå¥ã§ããŸãã äžèŠãªã³ãŒãã®åé€ã«ã€ããŠã¯ã ããªãŒã·ã§ãŒ ãã³ã° ãé«åºŠãªã¯ããŒãžã£ãŒã³ã³ãã€ã©ã®æé©åãããã³Lodash-babel-pluginãMoment.js ãªã©ã®ã©ã€ãã©ãªçšã®Webpack ContextReplacementPluginãªã©ã®ã©ã€ãã©ãªçšã®å¯Ÿå¿ãããã©ã°ã€ã³ãåç §ããŠãã ããã babel-preset-envãšbrowserlistã䜿çšããŠãææ°ã®ãã©ãŠã¶ãŒã§ã®ç¿»èš³ãåé¿ããŸãã äžçŽéçºè ã¯ã Webpackãã³ãã«ãæ éã«åæããŠãäžèŠãªäŸåé¢ä¿ãåé€ã§ããŸãã
- ãããã¯ãŒã¯ãã©ãã£ãã¯ãæžããããã®ãã£ãã·ã¥ ã æé©ãªã¹ã¯ãªããã®æå¹æéïŒmax-ageïŒã決å®ããå€æŽãããŠããªããã€ããéä¿¡ããªãããã«æ€èšŒããŒã¯ã³ïŒETagïŒãæäŸããŸãã ãµãŒãã¹ã¯ãŒã«ãŒããã£ãã·ã¥ãããšãã¢ããªã±ãŒã·ã§ã³ããããã¯ãŒã¯ã®åæ¢ã«å¯ŸããŠå埩åãæã¡ãV8ã®ã³ãŒããã£ãã·ã¥ãªã©ã®æ©èœãžã®æè¿ãããã¢ã¯ã»ã¹ãæäŸã§ããŸãã ãã¡ã€ã«åãããã·ã¥ããããšã§é·æãã£ãã·ã¥ã«ã€ããŠåŠç¿ããŸã ã
ãŠãŒã¶ãŒã«æž¡ãããJavaScriptã³ãŒãã®éãæžããããã®éèŠãªãã³ã
解æ/ã³ã³ãã€ã«
JavaScriptã³ãŒããããŠã³ããŒãããåŸã æãéèŠãªã³ã¹ãã®1ã€ã¯ãJSãšã³ãžã³ã§ãã®ã³ãŒãã解æ/ã³ã³ãã€ã«ããæéã§ãã Chrome DevToolsã§ã¯ã解æãšã³ã³ãã€ã«ã¯ããã©ãŒãã³ã¹ããã«ã®é»è²ã®ã¹ã¯ãªããæéã®äžéšã§ãã
[ããã ã¢ãã]ã¿ããš[ã³ãŒã«ããªãŒ]ã¿ãã§ã解æãšã³ã³ãã€ã«ã®æ£ç¢ºãªæéã確èªã§ããŸãã
Chrome DevToolsããã©ãŒãã³ã¹ããã«>ããã ã¢ããã V8 Runtime Call Statsæ©èœãã¢ã¯ãã£ãã«ãããšã解æããã³ã³ã³ãã€ã«ã®æ®µéã«è²»ããããæéã衚瀺ãããŸã
ãããããªããããéèŠãªã®ã§ããããïŒ
ã³ãŒãã®è§£æãšã³ã³ãã€ã«ã«å€å€§ãªæéãè²»ãããšããŠãŒã¶ãŒããµã€ããæäœããéã®é 延ãå€§å¹ ã«å¢å ããå¯èœæ§ããããŸãã éä¿¡ããJavaScriptã³ãŒããå€ãã»ã©ããµã€ãããŠãŒã¶ãŒã®ã¢ã¯ã·ã§ã³ã«å¿çãå§ãããŸã§ã®è§£æããã³ã³ã³ãã€ã«ãã§ãŒãºãé·ããªããŸãã
ãã€ãåäœã§æ¯èŒãããšã JavaScriptåŠçã¯ãåçã®ãµã€ãºã®ç»åãŸãã¯ãã©ã³ãããããã©ãŠã¶ãŒã®ã³ã¹ããé«ããªããŸã -ãã ããŒã«
JavaScriptãšæ¯èŒããŠãåããµã€ãºã®ç»åã«ãå€æ°ã®åŠçã³ã¹ããããããŸãïŒãããããã³ãŒãããå¿ èŠããããŸãïŒïŒããå¹³åçãªæºåž¯é»è©±ã®æ©åšã§ã¯ãããŒãžã®å¯Ÿè©±æ§ã«æªåœ±é¿ãäžããã®ã¯JSã§ãã
JavaScriptãšç»åãã€ãã¯ãªãœãŒã¹ãç°ãªãæ¹æ³ã§äœ¿çšããŸãã éåžžãç»åã¯ã¡ã€ã³ã¹ããªãŒã ããããã¯ããããã³ãŒãããã³ã©ã¹ã¿ã©ã€ãºäžã«ã€ã³ã¿ãŒãã§ã€ã¹ãããªãŒãºããŸããã ãã ããJSã¯ã解æãã³ã³ãã€ã«ãã³ãŒãå®è¡ã«ããã察話æ§ã«åœ±é¿ãäžããããšãã§ããŸãã
é ã解æãšã³ã³ãã€ã«ã«ã€ããŠè©±ããšããã³ã³ããã¹ããéèŠã§ã-ããã§ã¯ãäžåã®æºåž¯é»è©±ã«ã€ããŠè©±ããŠããŸãã éåžžã®ãŠãŒã¶ãŒã¯ãL2 / L3ãã£ãã·ã¥ããªããã¡ã¢ãªãéãããŠããå Žåã§ããCPUãšGPUãé ãé»è©±ã䜿çšã§ããŸãã
ãããã¯ãŒã¯æ©èœãšããã€ã¹æ©èœã¯åžžã«äžèŽãããšã¯éããŸããã åªããå ãã¡ã€ããŒãã£ãã«ã䜿çšããŠãããŠãŒã¶ãŒã¯ãããã€ã¹ã«ä»å±ããJavaScriptã解æããã³è©äŸ¡ããããã«åªããCPUãæã£ãŠããå¿ èŠã¯ãããŸããã éããŸãçã§ã...ã²ã©ããããã¯ãŒã¯æ¥ç¶ã§ãããéåžžã«é«éãªããã»ããµã§ãã -ã¯ãªã¹ããã¡ãŒã»ãã¯ã¹ã¿ãŒãLinkedIn
ã JavaScriptèµ·åããã©ãŒãã³ã¹ ãã®èšäºã§ã匱ããŠåŒ·åãªããŒããŠã§ã¢ã§çŽ1ã¡ã¬ãã€ãã®è§£åãããïŒåçŽãªïŒJavaScriptã³ãŒãã®è§£ææéã«æ³šç®ããŸããã æéã®ã¹ããŒããã©ã³ãšå¹³åã®éãã¯ã解æ/ã³ã³ãã€ã«æéã®2ã5åã§ãã
ç°ãªãã¯ã©ã¹ã®PCããã³ã¢ãã€ã«ããã€ã¹ã§ã®1 MBã®JavaScriptãã³ãã«è§£ææéïŒgzipã§çŽ250 KBïŒ ã 解æã³ã¹ããèæ ®ããå ŽåãçŽ250 MBã®ãã¡ã€ã«ãçŽ1 MBã®JSã³ãŒãã«å±éããè¿œå ã³ã¹ããè¿œå ããå¿ èŠããããŸãã
CNN.comã®ãããªå®éã®ãµã€ãã¯ã©ãã§ããïŒ
ææ°ã®iPhone 8ã¯ãCNNã¹ã¯ãªããã®è§£æ/ã³ã³ãã€ã«ã«çŽ4ç§ããããŸãããå¹³åçãªé»è©±ïŒMoto G4ïŒã§ã¯çŽ13ç§ããããŸãã ããã¯ããŠãŒã¶ãŒããµã€ããšããåãããæ©äŒãåŸããŸã§ã®æéã«å€§ãã圱é¿ããŸãã
éåžžã®Androidã¹ããŒããã©ã³ã®Snapdragon 617ãšæ¯èŒããApple A11 Bionicãããã§ã®è§£ææé
ããã¯ããã±ããã«ããé»è©±ã ãã§ãªããäžèŠæš¡ã®æ©åšïŒMoto G4ãªã©ïŒã§ãã¹ãããããšã®éèŠæ§ã瀺ããŠããŸãã ãã ããã³ã³ããã¹ãã¯éèŠã§ãã ãŠãŒã¶ãŒãæã£ãŠããããã€ã¹ãšãããã¯ãŒã¯ã®ç¶æ ã«åãããŠæé©åããŸã ã
åæããŒã«ã¯ããµã€ãã®å®éã®ãŠãŒã¶ãŒãæã£ãŠããã¢ãã€ã«ããã€ã¹ã®ã¯ã©ã¹ã衚瀺ã§ããŸãã ããã«ãããCPU / GPUã®å®éã®å¶éãç解ããããšãã§ããŸãã
JavaScriptã®åºè·ãå€ãããŸããïŒ ãŸããå€å:)
HTTPã¢ãŒã«ã€ãïŒçŽ50äžãµã€ãïŒã¯ã ã¢ãã€ã«ãµã€ãã§ã®JavaScriptã®äœ¿çšã瀺ããŠããŸã ã ãããŠããµã€ãã®50ïŒ ãã€ã³ã¿ã©ã¯ãã£ãã«ãªããŸã§ã«14ç§ä»¥äžãããããšãããããŸãã ãããã®ãµã€ãã¯ãJSã®è§£æãšã³ã³ãã€ã«ã ãã§æ倧4ç§ããããŸãã
JSããã®ä»ã®ãªãœãŒã¹ãããŒãããŠåŠçããã®ã«å¿ èŠãªæéãèæ ®ãããšããŠãŒã¶ãŒããããªãŒãºè§£é€ãããã®ãåŸ ããã«ããŒãžãé¢ããããšã¯é©ãããšã§ã¯ãããŸããã ããã«ã¯ééããªãæ¹åã®äœå°ããããŸãã
éèŠã§ãªãJavaScriptãããŒãžããåé€ãããšãããŒãæéãCPUéäžåã®è§£æ/ã³ã³ãã€ã«ãããã³æœåšçãªã¡ã¢ãªãªãŒããŒã©ã³ãåæžãããŸãã ãŸããããŒãžãã€ã³ã¿ã©ã¯ãã£ãã¢ãŒãã«å ¥ãã®ãéããªããŸãã
ãªãŒãã¿ã€ã
解æãšã³ã³ãã€ã«ã ãã§ã¯ä»£äŸ¡ãããããŸãã JavaScriptã®å®è¡ïŒè§£æ/ã³ã³ãã€ã«åŸã®ã³ãŒãå®è¡ïŒã¯ãã¡ã€ã³ã¹ã¬ããã§å®è¡ãããæäœã®1ã€ã§ãã ãªãŒãã¿ã€ã ãé·ããšããŠãŒã¶ãŒããµã€ããæäœã§ãããŸã§ã®æéã«ã圱é¿ããŸãã
ã¹ã¯ãªããã50ããªç§ããé·ãå®è¡ãããå Žåããµã€ããšã®å¯Ÿè©±ã®éå§ãŸã§ã®æéã¯ãJSã®ããŠã³ããŒããã³ã³ãã€ã«ãããã³å®è¡ã«ãããæéå šäœã§å¢å ããŸã-Alex Russell
ããã«å¯ŸåŠããããã«ãJavaScriptãå°ããªæçã§æž¡ããŠãã¡ã€ã³ã¹ã¬ãããé·æéãã£ããã£ããªãããã«ããããšã¯çã«ããªã£ãŠããŸãã ã¹ã¯ãªããã®å®è¡æéãæé©åããæ¹æ³ãåŠã³ãŸãã
JavaScripté ä¿¡ãé«éåããæ¹æ³
JavaScriptã®è§£æ/ã³ã³ãã€ã«ãšãããã¯ãŒã¯çµç±ã®éä¿¡ã®æéãççž®ããããšãç®æšã§ããå Žåãã«ãŒãããŒã¹ã®ãã£ã³ãã³ã°ãPRPLãªã©ã®äŸ¿å©ãªãã¯ããã¯ããããŸã ã
PRPLã¯ãã³ãŒãããã©ã°ã¡ã³ãã«ç©æ¥µçã«åå²ããŠãã£ãã·ã¥ããããšã«ããã察話æ§ãæé©åããããã®ææ³ã§ãã
ã©ã®ãããªå¹æãåŸããããèŠãŠã¿ãŸãããã
V8 Runtime Call Statsã䜿çšããŠã人æ°ã®ããã¢ãã€ã«ãµã€ããšããã°ã¬ãã·ãWebã¢ããªã±ãŒã·ã§ã³ã®èªã¿èŸŒã¿æéãåæããŸããã ã芧ã®ãšããã解ææéïŒãªã¬ã³ãžè²ã§è¡šç€ºïŒã¯æéã³ã¹ãã®å€§ããªéšåãå ããŠããŸãã
Wego Webãµã€ãã¯PRPLã䜿çšãã解ææéãäœãæããããšè©Šã¿ãéåžžã«è¿ éã«å¯Ÿè©±ããŸãã ãªã¹ããããŠããä»ã®ãµã€ãã®å€ãã¯ãJSã³ã¹ããåæžããããã«ãåå²ã³ãŒããšããã©ãŒãã³ã¹äºç®ã䜿çšããŠããŸãã
ãã®ä»ã®è²»çš
JavaScriptã¯ãå€ãã®ç¹ã§ããã©ãŒãã³ã¹ã«åœ±é¿ãäžããå¯èœæ§ããããŸãã
- ã¡ã¢ãªã ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®ããã«ãããŒãžããã£ããããããšããããŸãã ãã©ãŠã¶ãŒãã¡ã¢ãªãå¿ èŠãšããå ŽåãJSã®å®è¡ã¯äžæåæ¢ãããããããã©ãŠã¶ãŒã®ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãé »ç¹ã«å®è¡ããããšãå¿ èŠä»¥äžã«å®è¡ãåæ¢ããå ŽåããããŸãã ããŒãžã®ã¹ã ãŒãºãªç§»åãç¶æããããã«ãã¡ã¢ãªãªãŒã¯ãé »ç¹ãªã¬ããŒãžã³ã¬ã¯ã·ã§ã³ã®äžæåæ¢ãé¿ããŸãã
- JavaScriptãé·æéå®è¡ãããšã¡ã€ã³ã¹ã¬ããããããã¯ãããããŒãžãããªãŒãºããŸãã
requestAnimationFrame()
requestIdleCallback()
ã䜿çšããŠã³ãŒããããŒãã«åå²ããããšã§ããã®åé¡ã«å¯ŸåŠã§ããŸãã
ããã°ã¬ãã·ãããŒãã¹ãã©ãã
å€ãã®ãµã€ãã¯ãã€ã³ã¿ã©ã¯ãã£ãæ§ãéããŠã³ã³ââãã³ãã®å¯èŠæ§ãæé©åããŸãã 倧èŠæš¡ãªJavaScriptãã³ãã«ã§ã¬ã³ããªã³ã°ããã°ããéå§ããããã«ãéçºè ã¯ãµãŒããŒåŽã¬ã³ããªã³ã°ã䜿çšããããšããããŸãã JavaScriptãæçµçã«åŠçããããšãã«ç»åããæŽæ°ãããŸãã
泚æããŠãã ãã-ãã¹ãŠã«äŸ¡æ ŒããããŸãã 1ïŒåºæ¬çã«ããã倧ããªHTMLå¿çãéä¿¡ããŸããããã¯ã察話æ§ã«åœ±é¿ãäžããå¯èœæ§ããããŸãã 2ïŒãŠãŒã¶ãŒãä¿¡é Œã§ãããéªæªãªè°·ãã«æŸçœ®ããããšãã§ããŸããå®éã«ã¯ãJavaScriptåŠçãå®äºãããŸã§ãåæ¹åæ§ã®ååã¯å©çšã§ããŸããã
ããã°ã¬ãã·ãããŒãã¹ãã©ããã¯ããã®ã¢ãããŒããããåªãããªãã·ã§ã³ã§ãã æå°éã®æ©èœãåããããŒãžïŒãã®ããã»ãŒãžã§æãéèŠãªHTML / JS / CSSã®ã¿ã§æ§æãããŠããŸãïŒãéä¿¡ããŸãã æ®ãã®ãªãœãŒã¹ãå°çãããšãã¢ããªã±ãŒã·ã§ã³ã¯ããããé 延ããŒãããè¿œå æ©èœãããã¯è§£é€ããŸãã
ããã°ã¬ãã·ãããŒãã¹ãã©ãã ãããŒã«ã«ã€ã¹ã«ããã€ã©ã¹ã
ç»é¢ã«è¡šç€ºãããŠããå 容ã«å¿ããŠã³ãŒããããŠã³ããŒãããããšã¯ãæ¬åœã®ç®æšã§ãã PRPLãšããã°ã¬ãã·ãããŒãã¹ãã©ããã¯ã圌女ã«è¿ã¥ãã®ã«åœ¹ç«ã€ãã¯ããã¯ã§ãã
çµè«
现ããã£ãã«ã§ã¯äŒéãµã€ãºãéèŠã§ãã 解ææéã¯ãCPUã匱ãããã€ã¹ã«ãšã£ãŠéèŠã§ãã æå°éã®ããã©ãŒãã³ã¹ãç®æããŠåªåããå¿ èŠããããŸãã
ããŸããŸãªäŒæ¥ããJavaScriptã®è»¢éã解æãããã³ã³ã³ãã€ã«ã®æéã«å³ããããã©ãŒãã³ã¹äºç®ãå°å ¥ããããšã§ãããçšåºŠã®æåãåããŠããŸãã ã¢ãã€ã«Webãµã€ãããã³ã¢ããªã±ãŒã·ã§ã³åãã®Alex Russelläºç®ã¬ã€ãããããèš±å¯ã§ããŸããïŒïŒçŸå®äžçã®ããã©ãŒãã³ã¹äºç®ããåç §ããŠãã ããã
ã¢ããªã±ãŒã·ã§ã³ããžãã¯çšã«JSã«ã©ã®ãããã®ã¹ããŒã¹ã確ä¿ããããèæ ®ãããšäŸ¿å©ã§ãã
ã¢ãã€ã«ããã€ã¹çšã®Webãµã€ããäœæããŠããå Žåã¯ãç¹å®ã®æ©åšã䜿çšããJavaScriptã®è§£æ/ã³ã³ãã€ã«æéãæå°éã«æããããã©ãŒãã³ã¹äºç®ãå®è£ ããŠãéçºè ãJavaScriptã³ã¹ãã远跡ã§ããããã«ããŸãã
ãªãã·ã§ãã«
JavaScriptã®äŸ¡æ Œã«é¢ããChrome Dev Summit 2017ã§ã®ç§ã®ãã¬ãŒã³ããŒã·ã§ã³ã ãã®åŸãPinterestãTinderãªã©ã®å®éã®ãµã€ãã䜿çšããŠããã©ãŒãã³ã¹ãåæãããŸãã