Linkurious Enterpriseã®äž»ãªæ©èœã®1ã€ã¯ãçŽ äººåãã«èšèšããããç¿åŸãšäœ¿çšãç°¡åãªã°ã©ãèŠèŠåã€ã³ã¿ãŒãã§ã€ã¹ã§ãã 2015幎ãã°ã©ããèŠèŠåããããã®æ¢åã®JavaScriptã©ã€ãã©ãªã®æ©èœã«äžæºãæããç¬èªã®ã©ã€ãã©ãªã§ããOgmaã®éçºãéå§ããŸããã
Ogmaã¯ããããã¯ãŒã¯æ§é ã®ã¬ã³ããªã³ã°ãç®çãšããã¬ã³ããªã³ã°ããã³èšç®ããã©ãŒãã³ã¹ã®JSã©ã€ãã©ãªã§ããD3.jsãSigma.jsãªã©ã®ä»ã®JavaScriptããŒã«ã䜿çšããŠãããã¯ãŒã¯æ§é ãã©ã®ããã«ã¬ã³ããªã³ã°ãããããèŠãããšããããããããŸããããããã®ããŒã«ã®æ©èœãäžè¶³ããŠããŸãããç§ãã¡ã䜿çšããŠãããœãªã¥ãŒã·ã§ã³ã«ã¯ãç¹å®ã®ããã©ãŒãã³ã¹èŠä»¶ãæºããããã«ãããã€ãã®ç¹å®ã®æ©èœãããããšãéèŠã§ããããµãŒãããŒãã£ã®ã©ã€ãã©ãªã§ã©ã¡ããèŠã€ãããŸããã§ããããã®ãããç¬èªã®ã©ã€ãã©ãªããŒãããéçºããããšã«ããŸããã
ä»äº
ãããã¯ãŒã¯æ§é ã®èŠèŠå
Ogmaã©ã€ãã©ãªã¯ãæå 端ã®ã¢ã«ãŽãªãºã ã䜿çšããããã«èšèšãããŠããŸããé«åºŠãªWebGLããŒã¹ã®ã¬ã³ããªã³ã°ãšã³ãžã³ãããã®æ·±éšã§äœ¿çšãããWebã¯ãŒã«ãŒãŸã§ããã®ãã¹ãŠã®ã³ã³ããŒãã³ãã¯ãå©çšå¯èœãªæé«ã®ãããã¯ãŒã¯ã¬ã³ããªã³ã°ããã©ãŒãã³ã¹ãæäŸããããšãç®çãšããŠããŸããç§ãã¡ã®ç®æšã¯ãé·æçãªã¿ã¹ã¯ãå®è¡ãããšãã«ã©ã€ãã©ãªãéåžžã«ã€ã³ã¿ã©ã¯ãã£ãã«ããã©ã€ãã©ãªã«å®è£ ãããŠããäž»èŠãªã°ã©ãèŠèŠåã¢ã«ãŽãªãºã ãè¿ éãã€å®å®ããŠæ©èœããããã«ããããšã§ããã
WebAssemblyïŒWasmïŒãã¯ãããžãŒã¯ãæåã«å ±åãããç¬éãããWebéçºè ã«ä»¥åã«å©çšå¯èœã ã£ããã®ãšæ¯ã¹ãŠéè²ã®ãªãã¬ãã«ã®ããã©ãŒãã³ã¹ãçŽæããŠããŸãããåæã«ãéçºè èªèº«ãæ°ãããã¯ãããžãŒã䜿çšããããã«é床ã®åªåãããå¿ èŠã¯ãããŸããã§ããã圌ãã¯ãã³ã³ãã€ã«åŸã«ãã©ãŠã¶ã§å®è¡ã§ãããç¥ã£ãŠããé«æ§èœèšèªã§ã³ãŒããæžãå¿ èŠããããŸããã
Wasmãã¯ãããžãŒãå°ãéçºãããåŸãå®è£ ããåã«è©ŠããŠã¿ãŠãããã€ãã®ããã©ãŒãã³ã¹ãã¹ããå®æœããããšã«ããŸãããäžè¬çã«ãæ¯ãè¿ããã«é«éã®Wasmãã¬ã€ã³ã«é£ã³èŸŒãåã«ãå®å šã«ãã¬ã€ããããšã«ããŸããã
Wasmã«ç§ãã¡ãæ¹ãã€ããã®ã¯ããã®ãã¯ãããžãŒãJavaScriptãããå¹ççã«ã¡ã¢ãªãšããã»ããµãªãœãŒã¹ã䜿çšããŠãåé¡ãããŸã解決ã§ããããšã§ããã
ç§ãã¡ã®ç 究
ç§ãã¡ã®ç 究ã¯ãåæ§ã®ããŒã¿æ§é ã䜿çšããŠããŸããŸãªèšèªã«ç°¡åã«ç§»æ€ã§ããã°ã©ããæäœããããšãç®çãšããã¢ã«ãŽãªãºã ã®æ€çŽ¢ããå§ãŸããŸããã
n-bodyã¢ã«ãŽãªãºã ãéžæããŸãããããã¯ããã©ãŒã¹ã°ã©ãã®èŠèŠåã¢ã«ãŽãªãºã ãæ¯èŒããããã®ããŒã¹ã©ã€ã³ãšããŠãã䜿çšãããŸãããã®ã¢ã«ãŽãªãºã ã«åŸã£ãŠå®è¡ãããèšç®ã¯ãèŠèŠåã·ã¹ãã ã®äžã§æããªãœãŒã¹ãæ¶è²»ããéšåã§ãããã®ãããªã·ã¹ãã ã®äœæ¥ã®ãã®éšåã以åãããå¹ççã«å®è¡ã§ããã°ãããã¯Ogmaã«å®è£ ãããŠãããã¹ãŠã®ãã©ãŒã¹ã°ã©ãèŠèŠåã¢ã«ãŽãªãºã ã«éåžžã«è¯ã圱é¿ãåãŒããŸãã
åºæº
åãã²ã©ãåããããŠãã³ãããŒã¯ããããŸãã
Max DeMarzi
ãæ£çŽãªããã³ãããŒã¯ãéçºããããšã¯ãã°ãã°äžå¯èœãªäœæ¥ã§ããäºå®ã人工çã«äœæãããç°å¢ã§ã¯ãçŸå®ã®äžçã«å žåçãªã·ããªãªãåçŸããããšã¯å°é£ã§ããè€éãªã·ã¹ãã ã«é©ããç°å¢ãäœæããããšã¯ãåžžã«éåžžã«å°é£ã§ããå®éãå®éšå®€ç°å¢ã§ã¯å€éšèŠå ãå¶åŸ¡ããã®ã¯ç°¡åã§ãããå®éã«ã¯ããœãªã¥ãŒã·ã§ã³ã®ãããã©ãŒãã³ã¹ããã©ã®ããã«èŠãããã¯ãå€ãã®äºæããªããã®ã®åœ±é¿ãåããŸãã
ç§ãã¡ã®å Žåããã³ãããŒã¯ã¯ãn-bodyã¢ã«ãŽãªãºã ã®å®è£ ã®ããã©ãŒãã³ã¹ã調ã¹ãããšã§ãæ確ã«å®çŸ©ãããåäžã®åé¡ã解決ããããšãç®çãšããŠããŸããã
ããã¯ãä¿¡é Œã§ããçµç¹ãããã©ãŒãã³ã¹ã枬å®ããããã«äœ¿çšãããæ確ã§ååã«ææžåãããã¢ã«ãŽãªãºã ã§ããããã°ã©ãã³ã°èšèªã
ä»ã®å ¬æ£ãªãã¹ããšåæ§ã«ãç§ãã¡ã¯ç 究ããããŸããŸãªèšèªã®ããã«ããã€ãã®ã«ãŒã«ãäºåã«å®çŸ©ããŠããŸãïŒ
- ã¢ã«ãŽãªãºã ã®ããŸããŸãªå®è£ ã§ã¯ãåæ§ã®ã³ãŒãæ§é ã䜿çšããå¿ èŠããããŸãã
- è€æ°ã®ããã»ã¹ãŸãã¯è€æ°ã®ã¹ã¬ããã䜿çšããããšã¯çŠæ¢ãããŠããŸãã
- SIMDã®äœ¿çšã¯çŠæ¢ãããŠããŸãã
- å®å®ããããŒãžã§ã³ã®ã³ã³ãã€ã©ã®ã¿ããã¹ããããŸãããã€ããªãŒãããŒã¿ãã¢ã«ãã¡ããã¬ã¢ã«ãã¡ãªã©ã®ãªãªãŒã¹ã䜿çšããããšã¯çŠæ¢ãããŠããŸãã
- åèšèªã«ã¯ãææ°ã®ã³ã³ãã€ã©ããŒãžã§ã³ã®ã¿ã䜿çšãããŸãã
ã«ãŒã«ã決å®ããåŸããã§ã«ã¢ã«ãŽãªãºã ã®å®è£ ã«é²ãããšãã§ããŸããããã ãããããè¡ãåã«ãããã©ãŒãã³ã¹ã調æ»ããèšèªãéžæããå¿ èŠããããŸããã
JSã®ç«¶åä»ç€Ÿ
Wasmã¯ããã©ãŠã¶ã§å®è¡ãããåœä»€ã®ãã€ããªåœ¢åŒã§ããããŸããŸãªããã°ã©ãã³ã°èšèªã§æžãããã³ãŒãã¯ããã®åœ¢åŒã«ã³ã³ãã€ã«ãããŸãã圌ãã¯Wasmã³ãŒãã人éãèªããã³ãŒããšããŠèšã£ãŠããŸãããWasmã§çŽæ¥ããã°ã©ã ãæžãããšã¯ãæ£æ°ã®äººãäžãããšãã§ãã決å®ã§ã¯ãããŸããããã®çµæããã³ãããŒã¯èª¿æ»ãå®æœãã以äžã®åè£ãéžæããŸããã
n-bodyã¢ã«ãŽãªãºã ã¯ãããã3ã€ã®èšèªã§å®è£ ãããŸãããããŸããŸãªå®è£ ã®ããã©ãŒãã³ã¹ããåºæ¬ã®JavaScriptå®è£ ã®ããã©ãŒãã³ã¹ãšæ¯èŒããŸããã
åã¢ã«ãŽãªãºã ã®å®è£ ã§ã¯ã1000ãã€ã³ãã䜿çšããç°ãªãå埩åæ°ã§ã¢ã«ãŽãªãºã ãå®è¡ããŸãããåããã°ã©ã ã»ãã·ã§ã³ãå®äºããã®ã«ãããæéã枬å®ããŸããã
ãã¹ãã¯ã次ã®ãœãããŠã§ã¢ãšãââãŒããŠã§ã¢ã䜿çšããŠå®è¡ãããŸããã
- NodeJS 12.9.1
- Chrome 79.0.3945.130ïŒå ¬åŒãã«ãïŒïŒ64ãããïŒ
- clang10.0.0-Cèšèªã§å®è£ ãããã¢ã«ãŽãªãºã ã®ããŒãžã§ã³
- emcc 1.39.6-ã³ãã³ãã©ã€ã³ããEmscriptenã³ã³ãã€ã©ãåŒã³åºãããã®ããã³ããšã³ããgcc / clangã®ä»£æ¿ãããã³ãªã³ã«ãŒ
- 貚ç©1.40.0
- wasm-pack 0.8.1
- AssemblyScript 0.9.0
- MacOS 10.15.2
- Macbook Pro 2017 Retina
- Intel Dual Core i5 2,3 GHzã8GB DDR3ã256GB SSD
ã芧ã®ãšããããã¹ãã§ã¯æéã®ã³ã³ãã¥ãŒã¿ãŒã§ã¯ãªããWasmãã€ãŸããã©ãŠã¶ãŒã®ã³ã³ããã¹ãã§å®è¡ãããã³ãŒãããã¹ãããŠããŸãããããŠããšã«ããããã©ãŠã¶ã¯éåžžãã·ã¹ãã ã§å©çšå¯èœãªãã¹ãŠã®ããã»ããµã³ã¢ãšãã¹ãŠã®RAMã«ã¢ã¯ã»ã¹ã§ããããã§ã¯ãããŸããã
ããã«é¢çœãããããã«ãåã¢ã«ãŽãªãºã å®è£ ã®ããã€ãã®ããŒãžã§ã³ãäœæããŸããã näœã·ã¹ãã ã®ããæç¹ã§ã¯ã座æšã®64ãããã®æ°å€è¡šçŸããããä»ã®æç¹ã§ã¯32ãããã§ããã
Rustã§ã¢ã«ãŽãªãºã ã®ãäºéãå®è£ ã䜿çšããããšã泚ç®ã«å€ããŸãããŸããWasmããŒã«ã䜿çšããã«ãããã€ãã£ããã§ãå®å šã§ãªããRustå®è£ ãäœæãããŸããããã®åŸãwasm-packã䜿çšããŠãè¿œå ã®ãå®å šãªãRustå®è£ ãäœæãããŸããããã®ã¢ã«ãŽãªãºã ã®å®è£ ã¯JSãšã®çµ±åã容æã§ãããWasmã®ã¡ã¢ãªãããé©åã«ç®¡çã§ããããšãæåŸ ãããŠããŸããã
ãã¹ã
2ã€ã®äž»èŠãªç°å¢ã§å®éšãå®è¡ããŸãããããã¯Node.jsãšãã©ãŠã¶ïŒChromeïŒã§ãã
ã©ã¡ãã®å Žåãããã³ãããŒã¯ã¯ãŠã©ãŒã ã¹ã¯ãªããã䜿çšããŠå®è¡ãããŸãããã€ãŸãããã¹ããå®è¡ããåã«ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãéå§ãããŠããŸããã§ãããåãã¹ãã®å®è¡åŸã«ã¬ããŒãžã³ã¬ã¯ã·ã§ã³ãå®è¡ãããšãããçµæã«å€§ããªåœ±é¿ã¯ãªãã£ãããã§ãã
AssemblyScriptã§èšè¿°ããããœãŒã¹ã³ãŒãã«åºã¥ããŠã以äžãçæãããŸããã
- ã¢ã«ãŽãªãºã ã®åºæ¬çãªJSå®è£ ã
- Wasmã¢ãžã¥ãŒã«ã
- Asm.jsã¢ãžã¥ãŒã«ã
asm.jsã¢ãžã¥ãŒã«ãasm.jsãšå®å šã«äºææ§ããªãã£ãããšã«æ³šæããã®ã¯èå³æ·±ãããšã§ããã¢ãžã¥ãŒã«ã®å é ã«ãuseasmããã£ã¬ã¯ãã£ããè¿œå ããããšããŸãããããã©ãŠã¶ãŒã¯ãã®æé©åãåãå ¥ããŸããã§ãããåŸã§ã䜿çšããbinaryenã³ã³ãã€ã©ããã³ãŒããasm.jsãšå®å šã«äºææ§ã®ãããã®ã«ããããšããŠããªãããšãçºèŠããŸããã代ããã«ãWasmã®ããçš®ã®å¹ççãªJSããŒãžã§ã³ã®åœ¢æã«çŠç¹ãåãããŸããã
æåã«Node.jsã§ãã¹ããå®è¡ããŸããã
Node.jsç°å¢ã§ã³ãŒããå®è¡ãã次
ã«ããã©ãŠã¶ãŒã§åãã³ãŒãã®ããã©ãŒãã³ã¹ã枬å®ããŸããã
ãã©ãŠã¶ã§ã®ã³ãŒãã®å®è¡
asm.jsããŒãžã§ã³ã®ã³ãŒãã®åäœãä»ã®ãªãã·ã§ã³ãããé ãããšã«ããã«æ°ä»ããŸããããã ãããããã®ã°ã©ãã§ã¯ãããŸããŸãªã³ãŒãããªã¢ã³ãã®çµæãã¢ã«ãŽãªãºã ã®åºæ¬çãªJSå®è£ ãšæ確ã«æ¯èŒããããšã¯ã§ããŸããããããã£ãŠããã¹ãŠãããããç解ããããã«ãããã«ããã€ãã®å³ãäœæããŸããã
ã¢ã«ãŽãªãºã ã®ä»ã®å®è£ ãšJSå®è£ ã®éãïŒ64ãããã®ãã€ã³ã座æšãæã€ãã³ãããŒã¯ããŒãžã§ã³ïŒ
ã¢ã«ãŽãªãºã ã®ä»ã®å®è£ ãšJSå®è£ ïŒ32ãããã®ãã€ã³ã座æšã
æã€ãã³ãããŒã¯ããŒãžã§ã³ïŒã®éã64ããããš32ãããã®ãã€ã³ã座æšãæã€ãã³ãããŒã¯ããŒãžã§ã³ã¯èããç°ãªããŸããããã«ãããJavaScriptã§ã¯æ°å€ã¯äž¡æ¹ã«ãªãåŸããšèããããã«ãªããããããŸãããäºå®ãã¢ã«ãŽãªãºã ã®å®è£ ã§ã¯ãæ¯èŒããŒã¹ãšããŠäœ¿çšãããJSã®æ°å€ã¯åžžã«64ãããã§ãããä»ã®èšèªããWasmã«ã³ãŒããå€æããã³ã³ãã€ã©ã¯ãããŸããŸãªæ¹æ³ã§ãã®ãããªæ°å€ãåŠçããŸãã
ç¹ã«ãããã¯asm.jsããŒãžã§ã³ã®ãã¹ãã«å€§ããªåœ±é¿ãäžããŸãããã€ã³ãã®åº§æšã32ãããã®ããŒãžã§ã³ã¯ãåºæ¬çãªJSå®è£ ãš64ãããã®æ°å€ã䜿çšããasm.jsããŒãžã§ã³ã®äž¡æ¹ãããããã©ãŒãã³ã¹ãå€§å¹ ã«å£ããŸãã
åã®å³ã§ã¯ãä»ã®ã³ãŒãããªã¢ã³ãã®ããã©ãŒãã³ã¹ãJSããªã¢ã³ããšã©ã®ããã«æ¯èŒãããããç解ããã®ã¯å°é£ã§ããããã¯ãAssemblyScriptã®ã¡ããªãã¯ãä»ã®ã¡ããªãã¯ãšããŸãã«ãç°ãªãããã§ãããããç解ããããã«ãasm.jsã®çµæãåé€ããŠå¥ã®å³ãäœæããŸããã
JSå®è£ ããã®ã¢ã«ãŽãªãºã ã®ä»ã®å®è£ éã®éãïŒasm.jsãªãã®64ãããã®ãã€ã³ã座æšãæã€ãã³ãããŒã¯ããŒãžã§ã³ïŒ
ã¢ã«ãŽãªãºã ã®ä»ã®å®è£ ãšJSå®è£ ã®éãïŒasm.jsã䜿çšããªã32ãããã®ãã€ã³ã座æšãæã€ãã³ãããŒã¯ããŒãžã§ã³ïŒ
æ°å€ã®è¡šçŸã®éãããä»ã®ããŒãžã§ã³ã®ãã¹ãã«åœ±é¿ãäžããŠããããã§ãããããã圌ãã¯ããŸããŸãªæ¹æ³ã§åœ±é¿ãäžããŸãããããšãã°ã32ãããã®æ°å€ïŒãããŒãïŒã䜿çšããCããªã¢ã³ãã¯ã64ãããã®æ°å€ïŒããã«ïŒã䜿çšããCããªã¢ã³ããããé ããªããŸããã32ãããçªå·ïŒf32ïŒã䜿çšãããã¹ãã®äž¡æ¹ã®RustããŒãžã§ã³ã¯ã64ãããçªå·ïŒf64ïŒã䜿çšããããŒãžã§ã³ãããé«éã«ãªããŸããã
ã¢ã«ãŽãªãºã ã®å®è£ ãäžååã§ããïŒ
äžèšã®ããŒã¿ã®åæã¯ã次ã®èãã瀺åããŠããå¯èœæ§ããããŸãããã¹ãããããã¹ãŠã®Wasmã¢ã»ã³ããªã®ããã©ãŒãã³ã¹ã¯JavaScriptå®è£ ã«éåžžã«è¿ããããWasmå®è£ ãã¢ã«ãŽãªãºã ã®ãã€ãã£ãå®è£ ã®ããã©ãŒãã³ã¹æ©èœã®ã¿ãåæ ããŠããå¯èœæ§ã¯ãããŸããïŒ
ã¢ã«ãŽãªãºã ã®ãã€ãã£ãå®è£ ãšJavaScriptå®è£ ã®æ¯èŒã¢ã«ãŽãªãºã å®è£ ã®
ãã€ãã£ãããŒãžã§ã³ã¯ãJavaScriptå®è£ ãããåžžã«é«éã§ãã
ãŸããWasmã¢ã»ã³ããªã¯ããã®ãããªã¢ã»ã³ããªã®äœæã«äœ¿çšãããã³ãŒãã®ãã€ãã£ãããŒãžã§ã³ãããé ãããšã«æ°ä»ããŸãããããã©ãŒãã³ã¹ã®éãã¯20ã50ïŒ ã§ããããã¯ã1000åã®å埩ã䌎ããã³ãããŒã¯ã®ççž®ããŒãžã§ã³ã§èŠã€ãããŸããã
Cå®è£ ãšå¯Ÿå¿ããWasmã¢ã»ã³ããª
Rustã®å®è£ ãšå¯Ÿå¿ããWasmãã«ã
wasm-packã䜿çšããŠäœæãããRustå®è£ ãããã³å¯Ÿå¿ããWasmã¢ã»ã³ããª
ãã€ãã£ãã³ãŒãã®å®è¡æéã枬å®ãããšãã«ãããã°ã©ã ã®ããŒãã«å¿ èŠãªæéãèæ ®ãããWasmããªã¢ã³ãã®å Žåããã®æéã¯èæ ®ãããŸããã§ããã
çµæ
åºæ¬çãªJSå®è£ ãšæ¯èŒããŠãã¢ã«ãŽãªãºã ã®2ã€ã®Rustå®è£ ã®ããã©ãŒãã³ã¹ã®åäžã¯å¹³åããŠ20ïŒ ã§ãããããã¯ããããRustã€ã¡ãŒãžã«ã¯é©ããŠããŸãããååŸã«ããã£ãåŽåã«æ¯ã¹ããšããã©ãŒãã³ã¹ã®åäžã¯å°ãªãããŸãã
ãããã®ãã¹ãããã©ã®ãããªçµè«ãå°ãåºãããšãã§ããŸããïŒãããŠãããã«ããã€ããããŸããJSã³ãŒããæ éã«äœæããããšã§ãããªãé«ãããã©ãŒãã³ã¹ãåŸãããšãã§ããä»ã®ããã°ã©ãã³ã°èšèªã«åãæ¿ããå¿ èŠããããŸããã
æ°ããããã°ã©ãã³ã°èšèªãåŠã¶ããšã¯åžžã«è¯ãããšã§ããããããæ°ããèšèªãåŠã¶ã®ã«ã¯ååãªçç±ãããã«éããããŸãããé«ã¬ãã«ã®èšèšã¢ãŒããã¯ãã£ã¯ãã³ã³ãã€ã©ããã€ã¯ãæé©åãããããã©ãŒãã³ã¹ã«ãšã£ãŠéèŠã§ãããããããã©ãŒãã³ã¹ããééã£ããçç±ã§ããããšããããããŸãã
å®éšãšããŠãJavaScriptãTypeScriptã«å€æŽããŠããã©ãŒã¹ã°ã©ãèŠèŠåã¢ã«ãŽãªãºã ã®å®è£ ãèšè¿°ããŸããããã®çµæãã³ãŒãããŒã¹ã®å質ã¯åäžããŸããããããã©ãŒãã³ã¹ã¯åäžããŸããã§ãããå ·äœçã«ããã©ãŒãã³ã¹ã枬å®ãããšããã移è¡åŸããããã«5ïŒ å¢å ããããšãããããŸããããããããã®çç±ã¯ã³ãŒãã®ãªãã¡ã¯ã¿ãªã³ã°ã§ãã
JavaScriptã®éçºãšããã©ãŒãã³ã¹ã®åé¡ã«èå³ãããå Žåã¯ããã®è¬æŒãã芧ã«ãªãããšããå§ãããŸããããã¯ãç§ãã¡ãåŸããã®ãšåæ§ã®çµæã«èãããŸããã
Webãããžã§ã¯ãã®ãéããéšåã®éçºã«ã©ã®ããã«ã¢ãããŒãããŸããïŒ