Webéçºè ã¯ãWebããŒãžã®ãµã€ãºãç°¡åã«å€§ãããªãããšãç¥ã£ãŠããŸãã ããããããŒãžã®èªã¿èŸŒã¿ã¯ãåã«ã¯ã€ã€ãä»ããŠãã€ãã転éããã ãã§ã¯ãããŸããã ãã©ãŠã¶ãã¹ã¯ãªãããããŒããããããããã解æã解éãå®è¡ããå¿ èŠããããŸãã ãã®èšäºã§ã¯ããã®ãã§ãŒãºãæ éã«æ€èšããã¢ããªã±ãŒã·ã§ã³ã®èµ·åãé ããªãåå ãšãã®ä¿®æ£æ¹æ³ã確èªããŸãã
æŽå²çã«ãç§ãã¡ã¯JavaScriptã®è§£æ/ã³ã³ãã€ã«ã®æé©åã«å€ãã®æéãè²»ãããŠããŸããã ããŒãµãŒã
<script>
å°éãããšããã«ãã¹ã¯ãªãããå³åº§ã«è§£æããã³å®è¡ããããšèããŠããŸãã ããããããã¯ããã§ã¯ãããŸããã V8ã®ç°¡ç¥å³ã¯æ¬¡ã®ãšããã§ãã
ããã¯ãäœæ¥ã³ã³ãã¢ã®çæ³çãªè¡šçŸã§ãã
ããã€ãã®éèŠãªãã§ãŒãºãèŠãŠã¿ãŸãããã
Webã¢ããªã±ãŒã·ã§ã³ã®èªã¿èŸŒã¿ãé ããªãã®ã¯äœã§ããïŒ
èµ·åäžãJavaScriptãšã³ãžã³ã¯ã¹ã¯ãªããã®è§£æãã³ã³ãã€ã«ãå®è¡ã«ããªãã®æéãè²»ãããŸãã ããã¯éèŠã§ãããšã³ãžã³ããããããªãé·ãæéè¡ããšãWebãµã€ããšã®ãŠãŒã¶ãŒã€ã³ã¿ã©ã¯ã·ã§ã³ã®éå§ãé ããããã§ãã ãã¿ã³ã衚瀺ãããŠããããæ°ç§ä»¥å ã«ã¯ãªãã¯ã«åå¿ããªããšä»®å®ããŸãã ããã«ãããUXãäœäžããå¯èœæ§ããããŸãã
Chrome Canaryã®V8ã©ã³ã¿ã€ã ã³ãŒã«çµ±èšã䜿çšãã人æ°ãµã€ãã®è§£æããã³ã³ã³ãã€ã«æéã ãã¹ã¯ãããã³ã³ãã¥ãŒã¿ãŒã®ã¹ããŒããã©ã³ã§ã¯ã解æãšã³ã³ãã€ã«ãããã«é ããªãããšã«æ³šæããŠãã ããã
èµ·åæéã¯ã ããã©ãŒãã³ã¹ã«ææãªã³ãŒãã«ãšã£ãŠéèŠã§ãã å®éãV8 JSãšã³ãžã³ã¯ãFacebookãWikipediaãRedditãªã©ã®ãµã€ãã®è§£æãšã³ã³ãã€ã«ã«å€ãã®æéãè²»ãããŠããŸãã
ãã³ã¯è²ã®é åïŒJavaScriptïŒã¯ãV8ãšBlink C ++ã®æäœã«è²»ããããæéããªã¬ã³ãžãšé»è²-解æãšã³ã³ãã€ã«ã®æéãåæ ããŠããŸã
å€ãã®ãµã€ãããã³ãã¬ãŒã ã¯ãŒã¯ã§ã¯ã解æãšã³ã³ãã€ã«ã匱ç¹ã§ãã 以äžã¯ãSebastian MarkbageïŒFacebookïŒããã³Rob WormaldïŒGoogleïŒã«ãã£ãŠåŒçšãããŠããŸãã
解æ/ã³ã³ãã€ã«ã¯å€§ããªåé¡ã§ãã ã¿ããªã«ããŒã¿ãå ±æããŠããããŸãã ãã ããåæã枬å®ããå¿ èŠããããŸãã
- @sebmarkbage
ãã®ããŒã¿ã¯ãDOMã«è§Šããåã«ãAngularã®äž»èŠãªã¹ã¿ãŒãã¢ããã³ã¹ããäž»ã«JSã解æãããããªæ¹æ³ã§ç解ããŠããŸãã
- @robwormald
Sam Sacconeãããã©ãŒãã³ã¹ã®èšç»ã«ãããJS解æã®ã³ã¹ããæããã«ããŸã
Webã®ãã¢ããªãã£ãã¯å¢å ããŠããŸã ã ã¹ããŒããã©ã³ã§ã®è§£æ/ã³ã³ãã€ã«ã¯ããã¹ã¯ãããã³ã³ãã¥ãŒã¿ãŒããã2ã5åé·ããªãå¯èœæ§ãããããšãç解ããããšãéèŠã§ã ã ããã«ãæäžäœã®ã¹ããŒããã©ã³ã®ããã©ãŒãã³ã¹ã¯ãMoto G4ãšã¯å€§ããç°ãªããŸãã ããã¯ããŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã®å質ããã¹ãããããã«ã代衚çãªæ©åšã§ãã¹ãããããšã®éèŠæ§ã匷調ããŠããŸãïŒãããã ãã§ãªãïŒïŒã
ç°ãªãã¯ã©ã¹ã®ãã¹ã¯ãããããã³ã¢ãã€ã«ããã€ã¹ã§1ãã±ããJavaScriptãã³ãã«ã解æããæé ã iPhone 7ãªã©ã®ã¹ããŒããã©ã³ã®ããã©ãŒãã³ã¹ã¯MacBook Proã«è¿ãããšã«æ³šæããŠãã ããããããã¬ã³ãžããã€ã¹ã§ã®ããã©ãŒãã³ã¹ã®äœäžãæ¯èŒããŠãã ããã
Webã¢ããªã±ãŒã·ã§ã³ã巚倧ãªããã±ãŒãžã䜿çšããŠããå Žåãã³ãŒãåå²ãããªãŒã·ã§ãŒãã³ã°ãService Workerãã£ãã·ã³ã°ãªã©ã®ææ°ã®é ä¿¡æè¡ãé©çšãããšãéåžžã«å€§ããªåœ±é¿ãäžããå¯èœæ§ããããŸãã äžæ¹ã äžåšçšã«äœæãããããŸãã¯å¹³å¡ãªã©ã€ãã©ãªã䜿çšããŠããå°ããªããã±ãŒãžã§ãã£ãŠããã³ã³ãã€ã«ãŸãã¯é¢æ°åŒã³åºãã§ã¡ã€ã³ã¹ã¬ãããé·æéã¹ã¿ãã¯ããããšããããŸã ã ããã«ããã¯ãã©ãã«ããããæ£ç¢ºã«ææ¡ããŠãå šäœåãè©äŸ¡ããããšãéèŠã§ãã
JavaScriptã®è§£æãšã³ã³ãã€ã«æéã¯ãå¹³åçãªãµã€ãã®ããã«ããã¯ã§ããïŒ
確ãã«ä»ããªãã¯èããŠããïŒãããããç§ã¯Facebookã§ã¯ãããŸãããã ãå¹³åçãªãµã€ãã®è§£æãšã³ã³ãã€ã«ã«ã¯ã©ããããæéãããããŸããïŒããšå°ããããšãã§ããŸãããã®è³ªåã調ã¹ãŠã¿ãŸãããã
ReactãAngularãEmberãVueãªã©ãããŸããŸãªã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯ã䜿çšããŠæ§ç¯ãããå€æ°ã®äœæ¥ãµã€ãïŒ6000以äžïŒ ã®ããã©ãŒãã³ã¹ã枬å®ããã®ã«2ãæãè²»ãããŸããã ãã¹ãã®ã»ãšãã©ã¯WebPageTestã§åçŸããããããèªåã§ç°¡åã«å®è¡ããããå©çšå¯èœãªçµæãââ泚ææ·±ã調ã¹ããã§ããŸãã ããã«ããã€ãã®çµè«ããããŸãã
ãã¹ã¯ãããïŒã±ãŒãã«æ¥ç¶ïŒã§8ç§åŸã«ãã¹ããŒããã©ã³ïŒ3GæèŒã®Moto G4ïŒã§16ç§åŸã«ã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¿ã©ã¯ãã£ãã«ãªããŸãã
ãã®çç±ã¯äœã§ããïŒ ãã¹ã¯ãããã§ã¯ãã»ãšãã©ã®ã¢ããªã±ãŒã·ã§ã³ã®èµ·åïŒè§£æ/ã³ã³ãã€ã«/å®è¡ïŒã«å¹³åã§çŽ4ç§ããããŸãã
ã¹ããŒããã©ã³ã§ã¯ã解ææéã¯ãã¹ã¯ããããããçŽ36ïŒ é·ããªããŸããã
誰ãã巚倧ãªJSããã±ãŒãžã䜿çšããŸãããïŒ æã£ãã»ã©å€§ããã¯ãããŸãããããŸã æ¹åã®äœå°ããããŸãã å¹³åããŠãéçºè ã¯ããŒãžã«gzipã§å§çž®ããã410 Kbããã±ãŒãžã䜿çšããŸããã ããã¯HTTPã¢ãŒã«ã€ãããŒã¿-ããŒãžãããå¹³å420 KB JSãšäžèŽããŠããŸãã äžéšã®ããªãŒã¯ã¯ãæ倧10 MBã®ã±ãŒãã«ã§éä¿¡ããŸããã
HTTPã¢ãŒã«ã€ãçµ±èš ïŒããŒãžãããå¹³å420 KB JavaScript
ã¹ã¯ãªããã®ãµã€ãºã¯éèŠã§ããã決å®çã§ã¯ãããŸããã 解æããã³ã³ã³ãã€ã«ã®æéã¯ãå¿ ãããã¹ã¯ãªããã®ãµã€ãºã«çŽç·çã«äŸåããããã§ã¯ãããŸããã äžè¬ã«ãããã³ã³ãã¯ããªJavaScriptããã±ãŒãžã§ã¯èªã¿èŸŒã¿ãé«éã«ãªããŸããïŒãã©ãŠã¶ãŒãããã€ã¹ãæ¥ç¶ã«ãã£ãŠç°ãªããŸãïŒã200 Kb JSïŒ== 200 Kbã§ããããã解æãšã³ã³ãã€ã«ã®æéã¯å€§å¹ ã«ç°ãªããŸãã
æå 端ã®JavaScript解æããã³ã³ã³ãã€ã«æé
Chrome Developer Toolkit
ã¿ã€ã ã©ã€ã³ïŒããã©ãŒãã³ã¹ããã«ïŒ>ããã ã¢ãã/ã³ãŒã«ã«ç§»åãããšãããªãŒ/ã€ãã³ããã°ã衚瀺ããããããã解æãšã³ã³ãã€ã«ã«è²»ããããæéãææ¡ã§ããŸãã ãã詳现ãªå³ïŒäŸãã°ã解æãäºå解æããŸãã¯é 延ã³ã³ãã€ã«ã®æéïŒã®ããã«ã V8ã®ã©ã³ã¿ã€ã åŒã³åºãã®çµ±èšãæå¹ã«ããããšãã§ããŸã ã ã«ããªã¢ã§ã¯ãããã¯æ¬¡ã®ããã«è¡ãããŸãããå®éšã>ãã¿ã€ã ã©ã€ã³ã®V8ã©ã³ã¿ã€ã åŒã³åºãçµ±èšãã
Chromeã§ã®ãã¬ãŒã¹
aboutïŒãã¬ãŒã¹ -Chromeã®äœã¬ãã«ãã¬ãŒã¹ããŒã«ã䜿çšãããšãdisabled-by-default-v8.runtime_statsã«ããŽãªã䜿çšããŠãV8ã®æéã«è²»ããããŠããããšã«ã€ããŠããæ·±ãçµè«ãåŒãåºãããšãã§ããŸãã ãšã³ãžã³ã«ã¯ãããŒã«ã䜿çšããããã®æ°ãã段éçãªã¬ã€ãããããŸãã
WebPageTest
WebPageTestã®Processing BreakdownããŒãžã«ã¯ãå«ãŸããŠããChrome> Capture Dev Tools TimelineããŒã«ã䜿çšããŠãã¬ãŒã¹ãããšãã®ãV8ãEvaluateScriptãããã³FunctionCallã§ã®ã³ã³ãã€ã«æéã«é¢ããããŒã¿ãå«ãŸããŠããŸãã
ãŸããã«ã¹ã¿ã ãã¬ãŒã¹ã«ããŽãªdisabled-by-default-v8.runtime_statsãèšå®ããããšã«ãããã©ã³ã¿ã€ã ã³ãŒã«çµ±èšãæœåºã§ããŸãïŒWPTã®Pat Minenã¯ããã©ã«ãã§ãããè¡ããŸãïŒïŒã
ããã®ã¡ãªããïŒ https : //gist.github.com/addyosmani/45b135900a7e3296e22673148ae5165b
ãŠãŒã¶ãŒã®ã¿ã€ãã³ã°
User Timing APIã䜿çšããŠè§£ææéã枬å®ã§ããŸã ã
ããã§ã¯ã3çªç®ã®
<script>
ã¯éèŠã§ã¯ãããŸããã ãã ããæåã®
<script>
2çªç®ã®
<script>
ããåé¢ããããšã§éèŠã«ãªã
<script>
ïŒ performance.markïŒïŒã¯
<script>
åã«å§ãŸã
<script>
ïŒã
ãã®ã¢ãããŒãã¯ãV8ããªããŒãµãŒããã®åŸç¶ã®åèµ·åã«åœ±é¿ãäžããå¯èœæ§ããããŸãã ããã¯ãã¹ã¯ãªããã®æåŸã«ã©ã³ãã ãªæååå€ãè¿œå ããããšã§åé¿ã§ããŸããããã¯ãNolan Lawsonã«ãããã³ãããŒã¯ã§ãåæ§ã®ããšãè¡ãããŸããã
JavaScriptã®è§£ææéã®åœ±é¿ã枬å®ããã«ã¯ãGoogleã¢ããªãã£ã¯ã¹ã䜿çšããŠåæ§ã®ã¢ãããŒãã䜿çšããŸãã
ã«ã¹ã¿ã 解æ枬å®ã«ãããããŒãžã«ã¢ã¯ã»ã¹ããå®éã®ãŠãŒã¶ãŒããã³ããã€ã¹ã®JavaScript解æã®æéã枬å®ã§ããŸã
DeviceTiming
DeviceTimingããŒã«ã¯ãå¶åŸ¡ãããç°å¢ã§ã¹ã¯ãªããã®è§£æ/ã³ã³ãã€ã«ã®æéã枬å®ããã®ã«åœ¹ç«ã¡ãŸãã ããŒã«ã«ã¹ã¯ãªããã¯ããŒã«ã©ãããŒã«é 眮ãããç°ãªãããã€ã¹ïŒã©ããããããã¹ããŒããã©ã³ãã¿ãã¬ããïŒããããŒãžã«ã¢ã¯ã»ã¹ãããã³ã«ã解æ/å®è¡æéãããŒã«ã«ã§æ¯èŒã§ããŸãã Daniel Espesetã«ããè¬æŒã ã¢ãã€ã«ããã€ã¹ã§ã®JS解æãšå®è¡ã®ãã³ãããŒã¯ ãã§ããã®ããŒã«ã«ã€ããŠè©³ãã説æããŠããŸãã
JavaScriptã®è§£ææéãççž®ããã«ã¯ã©ãããã°ããã§ããïŒ
- JavaScriptã®åæžã 解æããã¹ã¯ãªãããå°ãªãã»ã©ã解æ/ã³ã³ãã€ã«ãã§ãŒãºãçããªããŸãã
- ã³ãŒãåââå²ææ³ã¯ãããŒãžäžã§ãŠãŒã¶ãŒãã¬ã€ãããããã«å¿ èŠãªã³ãŒããé ä¿¡ããããã«ã®ã¿äœ¿çšããæ®ããã¬ã€ãžãŒã¢ãŒãã§èªã¿èŸŒã¿ãŸãã å€ãã®å Žåãããã¯å€§éã®JSã®è§£æãåé¿ããã®ã«åœ¹ç«ã¡ãŸãã ä»æ¥FlipkartãHousing.comãTwitterã§äœ¿çšãããŠããPRPLã®ãããªãã¿ãŒã³ã¯ããã®ã¢ãããŒããå®è£ ããã®ã«åœ¹ç«ã¡ãŸãã
- ã¹ã¯ãªããã¹ããªãŒãã³ã°ã䜿çšããŸãã V8ã§ã¯ãéçºè ã«éåæ/é 延ã䜿çšããŠã ã¹ããªãŒãã³ã°ã¹ã¯ãªããã®èªã¿èŸŒã¿ã䜿çšããŠè§£ææéã10ã20ïŒ ççž®ããããšãã§ããŸããã ããã«ãããå°ãªããšãHTMLããŒãµãŒã¯ãœãŒã¹ãããæ©ãæ€åºããã¿ã¹ã¯ãã¹ããªãŒãã³ã°ããŠã³ããŒãã¹ããªãŒã ã«æž¡ããããã¥ã¡ã³ãã®è§£æãé ãããããšã¯ã§ããŸããã çŸåšãããã¯ããŒãµãŒãããã¯ã¹ã¯ãªããã§ãå®è¡ãããŠãããä»ã®ã¿ã¹ã¯ã¯ãªããšæããŸãã ã¹ããªãŒããŒã¹ããªãŒã ã1ã€ããå ŽåãV8ã§ã¯ããã倧ããªãã±ãããæåã«ããŒãããããšããå§ãããŸãã
- ã©ã€ãã©ãªãšãã¬ãŒã ã¯ãŒã¯- äŸåé¢ä¿è§£æã®ã³ã¹ãã枬å®ããŸã ã å¯èœãªéããããé«éãªè§£æã§äŸåé¢ä¿ã«åãæ¿ããŸãïŒããšãã°ãReactã®ä»£ããã«ãèµ·åã«å¿ èŠãªãã€ãæ°ãå°ãªãã解æ/ã³ã³ãã€ã«ãé«éãªPreactãŸãã¯Infernoã䜿çšããããšããå§ãããŸãïŒã ããŒã«ã«ã€ã¹ã¯æè¿åœŒã®èšäºã§ãã¬ãŒã ã¯ãŒã¯ãç«ã¡äžããè²»çšã®åé¡ãæèµ·ããŸããã Sebastian Markbageã¯ãŸãããã¬ãŒã ã¯ãŒã¯ã®åæããŒãã®ã³ã¹ããæž¬å® ãã è¯ãæ¹æ³ã ææããŸãã -æåã«ãã¥ãŒãã¬ã³ããªã³ã°ãããããåé€ããŠããå床ã¬ã³ããªã³ã°ããŸããããã«ããããã®ã¹ã±ãŒã©ããªãã£ãç解ã§ããŸã ã æåã®ã¬ã³ããªã³ã°ã¯ãé 延ã³ã³ãã€ã«ãããã³ãŒãã®ãŠã©ãŒã ã¢ãããšããŠæ©èœãããã®å€§ããªããªãŒã¯ã¹ã±ãŒãªã³ã°ã®æ©æµãåããããšãã§ããŸãã
éžæããJavaScriptãã¬ãŒã ã¯ãŒã¯ãäºåã³ã³ãã€ã«ïŒAoTïŒããµããŒãããŠããå Žåãããã«ãã解æ/ã³ã³ãã€ã«æéãå€§å¹ ã«ççž®ãããŸãã ããšãã°ãããã¯Angularã¢ããªã±ãŒã·ã§ã³ã«åœ¹ç«ã¡ãŸãïŒ
ããŒã©ã³ã»ããŒãœã³ã«ããã¹ããŒãã Webããã©ãŒãã³ã¹ã®å±æ©ã®è§£æ±º ã
解æ/ã³ã³ãã€ã«ãé«éåããããã«ãã©ãŠã¶ã¯äœãããŸããïŒ
éçºè ãå®éã®çµ±èšãåéããŠãèµ·åé床ãæ¹åããæ¹æ³ãèŠã€ããã ãã§ã¯ãããŸããã V8ã®ãããã§ãæãå€ããã³ãããŒã¯ã®1ã€ã§ããOctaneã25ã®äººæ°ãµã€ãã®å®éã®ããã©ãŒãã³ã¹ã枬å®ããããã®è²§åŒ±ãªãããã·ã§ããããšãçºèŠãããŸããã ãªã¯ã¿ã³ã¯ãããã·ã«ããããšãã§ããŸãïŒ
- JSãã¬ãŒã ã¯ãŒã¯ã®å ŽåïŒéåžžã¯ã¢ã/ããªã¢ãŒãã£ãã¯ã³ãŒãã§ã¯ãããŸããïŒã
- ããŒãžã¢ããªã±ãŒã·ã§ã³ïŒå®ããŒãžã¢ããªïŒã®èµ·åçšïŒã»ãšãã©ã®ã³ãŒãã¯ãã³ãŒã«ããã§ãïŒã
ãããã®ã±ãŒã¹ã¯äž¡æ¹ãšãWebã«ãšã£ãŠéåžžã«éèŠã§ãããOctaneã¯ãã¹ãŠã®ã¿ã€ãã®ã¯ãŒã¯ããŒãã«é©ããŠããããã§ã¯ãããŸããã V8éçºããŒã ã¯ãèµ·åæéã®æ¹åã«å€ãã®æéãè²»ãããŸããã
V8ã®JavaScriptããã©ãŒãã³ã¹ã¯å¹Žããšã«çŽ25ïŒ åäžããŠããŸãã å®éã®ã¢ããªã±ãŒã·ã§ã³ã®ããã©ãŒãã³ã¹ã«ç·å¯ã«é¢äžããŠããŸãã
- @addyosmani
Octane-CodeloadããŒã¿ããå€æãããšãè€æ°ããŒãžã®è§£ææã®V8ã®ããã©ãŒãã³ã¹ã¯çŽ25ïŒ åäžããŠããŸãã
Pinterestã¯ãã®ç¹ã§æ¹åãããŸããã ãŸããè¿å¹Žã§ã¯ã解æãšã³ã³ãã€ã«ã®æéã«é¢ããŠãV8ã®å®æ§çãªæé·ã«é¢ããå€ãã®ä»ã®ç¢ºèªããããŸãã
ã³ãŒããã£ãã·ã³ã°
ã V8ã§ã®ã³ãŒããã£ãã·ã³ã°ã®äœ¿çš ãã®èšäºããã
Chrome 42ã«ã¯ãããŒãžã«æ»ã£ããšãã«ã¹ã¯ãªããã®æœåºã解æãã³ã³ãã€ã«ã®æé ãã¹ããããããããã«ãã³ã³ãã€ã«ãããã³ãŒãã®ããŒã«ã«ã³ããŒãä¿åããæ¹æ³ã§ããã³ãŒããã£ãã·ã³ã°ãå°å ¥ãããŸããã ç¹°ãè¿ãã¢ã¯ã»ã¹ãããšãChromeã§ã³ã³ãã€ã«ãçŽ40ïŒ é«éã«ãªããŸãããæ確ã«ããã¹ãããšãããã€ããããŸãã
- ã³ãŒããã£ãã·ã³ã°ã¯ã 72æé以å ã«2åå®è¡ãããã¹ã¯ãªããã«å¯ŸããŠæ©èœããŸãã
- Service Workerã¹ã¯ãªããã®å ŽåïŒ åãæ¡ä»¶ã
- Service Workerãä»ããŠã¹ã¯ãªãããªããžããªã«ä¿åãããã¹ã¯ãªããã®å Žåã æåã®å®è¡æã«ãã£ãã·ã¥ãããªã¬ãŒãããŸãã
ãããã£ãŠãã³ãŒãããã£ãã·ã¥ããå¿ èŠãããå ŽåãV8ã¯3åç®ã®ããŒããã解æãšã³ã³ãã€ã«ãã¹ãããããŸã ã
ãã®ã¡ã«ããºã ã§éã¶ããšãã§ããŸãïŒ chromeïŒ// flags /ïŒv8-cache-strategies-for-cache-storage ã ãã©ã°
â js-flags=profile-deserialization
Chromeãå®è¡ãããªããžã§ã¯ãããã£ãã·ã¥ããèªã¿èŸŒãŸããŠãããã©ããã確èªããããšãã§ããŸãïŒãã°ã§ã¯ããªããžã§ã¯ãã¯éã·ãªã¢ã«åã€ãã³ããšããŠè¡šç€ºãããŸãïŒã
1ã€ã®æ確åïŒç©æ¥µçã«ã³ã³ãã€ã«ãããã³ãŒãã®ã¿ããã£ãã·ã¥ãããŸãã äžè¬çã«ãããã¯ã°ããŒãã«å€ãèšå®ããããã«äžåºŠã ãå®è¡ããããããã¬ãã«ã®ã³ãŒãã§ãã é¢æ°å®çŸ©ã¯éåžžãé 延ããŠã³ã³ãã€ã«ãããåžžã«ãã£ãã·ã¥ãããããã§ã¯ãããŸããã IIFE ïŒãŠãŒã¶ãŒåããoptimize-js;ïŒïŒã貪欲ã«ã³ã³ãã€ã«ãããŠãããããV8ã³ãŒããã£ãã·ã¥ã«å«ãŸããŠããŸãã
ã¹ã¯ãªããã¹ããªãŒãã³ã°
ã¹ã¯ãªããã®ã¹ããªãŒãã³ã°ããŒãã䜿çšãããšãã¹ã¯ãªãããéåæãŸãã¯é 延ããŠè§£æããããŒãã®éå§æã«ã¹ã¯ãªãããå¥ã®ããã¯ã°ã©ãŠã³ãã¹ã¬ããã«ç§»åã§ããŸãã ããã«ãããããŒãžã®èªã¿èŸŒã¿ãçŽ10ïŒ é«éåã§ããŸãã äžèšã®ããã«ããã®ã¡ã«ããºã ã¯ã¹ã¯ãªããã®åæã«ãæ©èœããããã«ãªããŸããã
çŸåšãV8ã§ã¯ãããã¯ã°ã©ãŠã³ãã¹ã¬ããå ã®ãã¹ãŠã®ã¹ã¯ãªããã解æã§ããããŒãµãŒã
<script src=ââ>
ãããã¯ããŠããå Žåã§ã ãããã¯ãã¹ãŠã®äººã«å©çããããããŸãã 泚æç¹ã¯ãããã¯ã°ã©ãŠã³ãã¹ã¬ããã1ã€ã ãã§ãããããæåã«å€§ããª/éèŠãªã¹ã¯ãªãããåŠçããããšã¯çã«ããªã£ãŠããŸãã æ¹åãè¡ãããšãã§ããå Žæã決å®ããããã«ãå¿ ã枬å®ãè¡ã£ãŠãã ããã
<script defer>
<head>
ã«ããããããªãœãŒã¹ãäºåå®çŸ©ããŠãããã¯ã°ã©ãŠã³ãã¹ã¬ããã§è§£æã§ããŸãã
DevTools Timelineã䜿çšããŠãæ£ããã¹ã¯ãªããã«ã¹ããªãŒãã³ã°ãé©çšãããŠãããã©ããã確èªã§ããŸãã 解ææéã®ã»ãšãã©ãå ãã1ã€ã®å€§ããªã¹ã¯ãªãããããå Žåãã¹ããªãŒãã³ã°ããã®ã¹ã¯ãªããã«é©çšãããŠãããã©ããã確èªããã®ãçã«ããªã£ãŠããŸãã
解æãšã³ã³ãã€ã«ã®æ¹å
ããã³ã³ãã¯ãã§é«éãªããŒãµãŒãåŒãç¶ã䜿çšããŸããããã«ãããã¡ã¢ãªã解æŸãããããŒã¿æ§é ãããå¹ççã«äœ¿çšã§ããŸãã ä»æ¥ãV8ã®ã¡ã€ã³ã¹ã¬ããã§é 延ãçºçããäž»ãªçç±ã¯ã解æã³ã¹ãã®éç·åœ¢äŸåæ§ã§ãã UMDã®äŸïŒ
(function (global, module) { ⊠})(this, function module() { my functions })
V8ã¯ã¢ãžã¥ãŒã«ãæ£ç¢ºã«å¿ èŠã§ããããšãèªèããŠããªããããã¡ã€ã³ã¹ã¯ãªããã®ã³ã³ãã€ã«äžã«ã¢ãžã¥ãŒã«ãã³ã³ãã€ã«ããŸããã æçµçã«ã¢ãžã¥ãŒã«ãã³ã³ãã€ã«ããããšã«ãããšãããã¹ãŠã®å éšé¢æ°ãå解æããå¿ èŠããããŸãã ããã¯ãV8ã®è§£ææéã®éç·åœ¢æ§ã«ã€ãªãããŸãã æ·±ãNã®åé¢æ°ã¯Nå解æãããé 延ãçºçããŸãã
V8éçºè ã¯ãåæã³ã³ãã€ã«äžã«å éšé¢æ°ã«é¢ããæ å ±ã®åéã«ãã§ã«åãçµãã§ãããåŸç¶ã®ã³ã³ãã€ã«ã§ã¯å éšé¢æ°ãç¡èŠã§ããŸãã ããã«ãããã¢ãžã¥ã©ãŒïŒã¢ãžã¥ãŒã«ã¹ã¿ã€ã«ïŒé¢æ°ã®ããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸãã
詳现ã«ã€ããŠã¯ã The V8 ParserïŒsïŒ-DesignãChallengesãand Parsing JavaScript Betterãã芧ãã ããã
V8éçºè ã¯ãèµ·åæã«JavaScriptã³ã³ãã€ã«ã®äžéšãããã¯ã°ã©ãŠã³ãã«è»¢éããå¯èœæ§ãæ€èšããŠããŸã ã
JavaScriptãããªã³ã³ãã€ã«ããŸããïŒ
æ°å¹Žããšã«ããšã³ãžã³ã¯ã¹ã¯ãªãããããªã³ã³ãã€ã«ããæ¹æ³ãæäŸããããã衚瀺ãããã³ãŒãã®è§£æãã³ã³ãã€ã«ã«æéãè²»ããå¿ èŠããããŸããïŒã³ãŒãããããã¢ããããŸãïŒã 代ããã«ããã«ãäžãŸãã¯ãµãŒããŒåŽã§åçŽã«ãã€ãã³ãŒããçæã§ããŸãã ãã€ãã³ãŒããã¢ããªã±ãŒã·ã§ã³ã«æž¡ããšãããŒããé ããªãïŒãã€ãã³ãŒããããå€ãã®ã¹ããŒã¹ãå æããïŒãã»ãã¥ãªãã£ã®ããã«ãããããã³ãŒããšããã»ã¹ã«çœ²åããå¿ èŠããããŸãã çŸåšãV8éçºè ã¯ãããªã³ã³ãã€ã«ã¯ããŸãã¡ãªããããªããšèããŠããŸãã ãããã圌ãã¯æã¡äžã段éãå éããã¢ã€ãã¢ãè°è«ããããšã«å¯ŸããŠãªãŒãã³ã§ãã éçºè ã¯ãService Workerã§ãµã€ããã¢ããã°ã¬ãŒãããéã«ãã¹ã¯ãªããã®ã³ã³ãã€ã«ãšãã£ãã·ã¥ã«é¢ããŠV8ãããç©æ¥µçã«ããããšããŠããŸãã
FacebookãšAkamaiã§ã®ããªã³ã³ãã€ã«ã®èª¬æãããã³ãã®ããŒãã«é¢ããã¡ã¢ã¯ã ããã«ãããŸã ã
é 延解æã®ããã®Optimize JSãã©ã±ããã«ããããã¯
JavaScriptãšã³ãžã³ã«ã¯ãé 延解æãã¥ãŒãªã¹ãã£ãã¯ãè£ åãããŠããŸããã¹ã¯ãªããå ã®ã»ãšãã©ã®é¢æ°ã¯ãæ§æ解æãµã€ã¯ã«ãå®äºããåã«æºåãããŸãïŒããšãã°ãæ§æãšã©ãŒãæ€çŽ¢ããããïŒã ãã®ã¢ãããŒãã¯ãã»ãšãã©ã®ããŒãžã«JSé¢æ°ãå«ãŸããŠãããšããèãã«åºã¥ããŠããŸããJSé¢æ°ã¯ãå®è¡ããããšé 延ããŸãã
äºå解æãè¡ããšããã©ãŠã¶ãŒã«æäœéå¿ èŠãªæ å ±ãååšãããã©ããã ããæ©èœããã§ãã¯ããããããèµ·åãé«éåã§ããŸãã ããã¯ãIIFEã®äœ¿çšãšççŸããŠããŸãã ãšã³ãžã³ã¯ãšã³ãžã³ã®äºå解æãã¹ãããããããšããŸããããã¥ãŒãªã¹ãã£ãã¯ã¯åžžã«æ£ããæ©èœãããšã¯éããã optimize-jsã®ãããªããŒã«ã¯ãã®ãããªç¶æ³ã§åœ¹ç«ã¡ãŸãã
optimize-jsã¯ãã¹ã¯ãªãããäºåã«è§£æãããé¢æ°ãããã«å®è¡ãããããšãããã£ãŠããïŒãŸãã¯ãã¥ãŒãªã¹ãã£ãã¯ã®ãããã§æ³å®ããŠããïŒå Žåã¯æ¬åŒ§ãæ¿å ¥ããŸãã ããã«ãããå®è¡é床ãåäžããŸãã äžéšã®æ©èœïŒIIFEãªã©ïŒã§ã¯ããã®ãããªããã¯ã¯æ£åžžã«æ©èœããŸãã ä»ã®ãã®ã§ã¯ããã¹ãŠããã¥ãŒãªã¹ãã£ãã¯ã«äŸåããŸãïŒããšãã°ãBrowserifyãŸãã¯Webpackã§ã¯ããã¹ãŠã®ã¢ãžã¥ãŒã«ãç±å¿ã«ããŒãããããšæ³å®ãããŸãããããã¯åžžã«åœãŠã¯ãŸãããã§ã¯ãããŸããïŒã V8ã®éçºè ã¯ãå°æ¥ãã®ãããªããã¯ã®å¿ èŠæ§ããªããªãããšãæãã§ããŸãããä»æ¥ãããªããäœãããŠããã®ããç¥ã£ãŠãããªããããã¯äŸ¿å©ãªæé©åã§ãã
V8ã®äœæè ã¯ããšã©ãŒã®ã³ã¹ããåæžããããšã«ãåãçµãã§ããŸããããã«ãããå°æ¥çã«ã¯ãã©ã±ããã䜿çšããããã¯ã®å©ç¹ãæžãã¯ãã§ãã
ãããã«
éå§ããã©ãŒãã³ã¹ãéèŠã§ãã é ã解æãã³ã³ãã€ã«ãããã³å®è¡ã®çµã¿åããã¯ãè¿ éã«ããŒãããå¿ èŠãããããŒãžã®ããã«ããã¯ã«ãªãå¯èœæ§ããããŸãã ããŒãžã®ãããã®ãã§ãŒãºã®æéã枬å®ããŸãã ããããã¹ããŒãã¢ããããæ¹æ³ãèŠã€ããŸãã
ãããŠãç§ãã¡ã¯ãV8ã®åæããã©ãŒãã³ã¹ãæ¹åããããã«åŒãç¶ãåªåããŸãã çŽæããŸã;ïŒ
䟿å©ãªãªã³ã¯
- ããã©ãŒãã³ã¹ã®èšç»
- Nolan Lawsonã«ããWebããã©ãŒãã³ã¹ã®å±æ©ã®è§£æ±º
- JS解æãšå®è¡æé
- JavaScriptã®è§£æãšè² è·ã®æž¬å®
- ãã©ãã¯ããã¯ã¹ã®é梱ïŒã¢ãã€ã«ããã€ã¹ã§ã®JS解æãšå®è¡ã®ãã³ãããŒã¯ ïŒ ã¹ã©ã€ã ïŒ
- ãã¹ãŠãéèŠãªå ŽåãäœããããŸããïŒ
- åŸæ¥ã®JavaScriptãã³ãããŒã¯ã«é¢ããçå®
- ãã©ãŠã¶ãããŒãžã®èªã¿èŸŒã¿ããšã«JavaScriptã解æãã