asm.js

16
asm.js 전용우

Upload: yongwoo-jeon

Post on 15-Jan-2015

566 views

Category:

Technology


0 download

DESCRIPTION

asm.js에 대한 내용

TRANSCRIPT

Page 1: asm.js

asm.js

전용우

Page 2: asm.js

asm.js란?

• 성능을 높일 수 있는 자바스크립트 서브셋

JavaScript

asm.js

TypeScript superset

subset

Page 3: asm.js

왜 asm.js가 HOT한가?

• Mozilla와 Epic이 Unreal Engine3을 포팅

Page 4: asm.js

Unreal Engine3의 포팅 process

C++

IR Link

JS

WebGL

EMScripten

LLVM Clang

asm.js

Page 6: asm.js

function DiagModule(stdlib, foreign, heap) { "use asm"; // Variable Declarations var sqrt = stdlib.Math.sqrt; // Function Declarations function square(x) { x = +x; return +(x*x); } function diag(x, y) { x = +x; y = +y; return +sqrt(square(x) + square(y)); } return { diag: diag }; }

Math WebGL heap

var diag = DiagModule({ Math: Math }).diag; alert(diag(10, 100));

Page 7: asm.js

asm.js의 특징

• 모든 브라우저에서 동작

• 제한된 타입(숫자)만 가능 (링크)

• 직접 heap을 만들어서 메모리 관리 (링크)

Page 8: asm.js

왜 성능이 좋은가?

• 고정타입

– e|0 (integer), +a(double)

–엔진에서는 “use asm”이라고 되어 있으면 타입이 정적이라고 판단하여 AOT 컴파일(ahead-of-time compile)함.

• 메모리를 직접 관리

– heap을 구현하여 malloc과 free와 유사하게 관리

Page 9: asm.js
Page 10: asm.js

그럼, 만들어 볼까요?

function asmTest(){ "use asm"; }

Page 11: asm.js

asm.js는 사람이 개발하는 코드가 아님

Page 12: asm.js

asm.js는 주로 컴파일 된 코드

emscripten

LLJS

CoffeeScript

TypeScript

Dart

asm.js

pyjamas

GWT

Script#

Page 13: asm.js

한계

• 여전히 느린 성능

• 웹 개발하고는 거의 상관없음

• 굉장히 static함

• 개발과 디버깅 언어가 다름

• 결과가 JS일뿐 바이트 코드에 가깝다

• 차라리 JS개발의 성능을 올리는 게 좋다

Page 14: asm.js

차세대 웹 게임의 가능성을 보여줌

Page 15: asm.js

감사합니다

Page 16: asm.js

Resource

• http://ejohn.org/blog/asmjs-javascript-compile-target/

• http://kripken.github.io/mloc_emscripten_talk

• http://gigazine.net/news/20130322-firefox-asmjs/

• https://blog.mozilla.org/luke/2013/03/21/asm-js-in-firefox-nightly/

• http://kripken.github.io/ammo.js/examples/new/ammo.html

• http://jlongster.com/Compiling-LLJS-to-asm.js,-Now-Available-

• http://blog.izs.me/post/10213512387/javascript-is-not-web-assembly

• https://github.com/tonyg/js-nacl#readme

• http://mrale.ph/blog/2013/03/28/why-asmjs-bothers-me.html

• https://news.ycombinator.com/item?id=5456506

• https://news.ycombinator.com/item?id=5455045

• https://twitter.com/mraleph/status/317230108849098752

• http://mbebenita.github.io/LLJS/

• https://news.ycombinator.com/item?id=5486605

• https://blog.mozilla.org/javascript/2013/04/05/the-baseline-compiler-has-landed/

• http://kripken.github.io/mloc_emscripten_talk/gindex.html

• http://engineering.imvu.com/2013/04/05/multiplatform-c-on-the-web-with-emscripten/

• http://blog.brackets.io/2013/04/05/typeaware-javascript-code-intelligence/