SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
JSXdeveloping a statically-typed programming language for the Web 	
DeNA Co., Ltd.
Kazuho Oku
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 2
Agenda	
n JSX
n a statically-typed programming language
n that gets optimizing-compiled into JavaScript
n Binding W3C standards to JSX
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 3
About me	
n Name: Kazuho Oku
n Career:
n Palmscape / Xiino – world's first web browser for
Palm OS (1997-2004)
n R&D specialist at Cybozu Labs, Inc. (2005-2010)
n Japanize – collaborative UI localization service for the Web
n Greasemetal – world's first Google Chrome extension
n Q4M - message queue plugin for MySQL
n used by largest SNSs in Japan
n memcached plugin for MySQL
n working for DeNA Co., Ltd. (2010-)
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 4
About DeNA Co., Ltd.	
n Operator of Mobage
n one of the largest mobile gaming platforms in
Japan
n many games are developed by our partners
n games run on web browsers and mobile apps.
n we use JavaScript for writing app-based games as well
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 5
Problems of JavaScript	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 6
Large-scale Applications using JavaScript	
n state-of-the-art apps with more than
100k LOC	
n Kintone (Cybozu)
n Cloud web database
n similar cases with social game apps.
n > 5MB of .js after minified
n developed by large team
n > 10 members	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 7
JavaScript – the Good Parts	
n clear language design with specification	
n works on any web browser	
n very fast – thanks to the competition
n small and primitive language spec.
n prototype-based OO	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 8
JavaScript – the not-so-good Parts	
n low productivity	
n cannot find a bug before execution
n great variety in coding style
n hard to share the best practice	
n thus hard to write high-quality code	
n slow execution speed
n compared to native	
n high memory consumption	
n slow startup	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 9
The reason – JavaScript is a dynamic language	
n error-check only at runtime	
→ negative impact to productivity and quality	
n adaptive compilation	
→ negative impact on execution speed, startup
speed, memory footprint
n no heavy compiler optimizations	
n optimizations possible by JavaScript JIT engines have
their limits / overheads	
→ negative impact on execution speed	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 10
The Solution	
n Develop a dialect of JavaScript, that…
n enforces static types to JavaScript	
n like ActionScript 3 / EcmaScript 4
n optimize while translating to JavaScript	
n so that it would run faster than JavaScript!	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 11
JSX	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 12
The Goal fo JSX	
n an excellent programming language for
the web browsers
n run faster than JavaScript, on any web browser	
n important for browser-based games on smartphones	
n higher productivity than JavaScript
n easy to learn / maintain
n esp. for JavaScript programmers	
n esp. in medium to large-scale development	
n help writing high-quality code than in JavaScript	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 13
Design Principles of JSX	
n fully statically-typed	
n detect as many errors as possible at compile-time	
n leads to higher productivity and better quality
n provide optimizing compiler using the type information	
n expressions and statements are:
JavaScript + type annotations	
n easy to learn	
n no overhead by conversion to JavaScript	
n inject helper-code for debugging during compile
n Class-based OO	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 14
The Language	
class Point {	
var x = 0; // x is a "number"	
var y = 0; // y is a "number"	
	
function constructor() {	
}	
	
function constructor(x : number, y : number) {	
this.x = x;	
this.y = y;	
}	
	
override function toString() : string {	
return this.x as string + "," + this.y as string;	
}	
}	
	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 15
Performance Benchmarks	
n Box2D	
n convert box2d.js to JSX and measure the fps	
n iOS 5.0 – 12% speed-up
n Android 2.3 – 29% speed-up
n  AOBench
n  from http://spheresofa.net/blog/?p=757	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web
0 0.5 1 1.5 2
JavaScript
JSX
TypeScript
Haxe
処理速度	
iOS
Android
16
Minify	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web
n Minify is safe and more effective thanks
to the type information	
0" 0.2" 0.4" 0.6" 0.8" 1" 1.2"
Total"
ngCore"HTML5"
JSX"
v8bench.jsx"
byte%size%of%generated%code(ra2o)%
Impact%of%Minifica2on
jsx"AArelease"
jsx"AArelease"|"uglifyjs"
jsx"AArelease"|"esmangle"
jsx"AArelease"AAminify"
17
Debugging on Chrome	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 18
Automatic Completion	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 19
Integrated Test Framework	
// to run: jsx --test hello.jsx
	
import "test-case.jsx";
class _Test extends TestCase {
function test1() :void {
this.expect("hello").toBe("hello");
this.expect("world").toBe("world");
}
function test2() :void {
this.expect(42).toBe(42);
}
}
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 20
Profiler	
n works on any runtime with XHR support	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 21
Supported Optimization Methods	
n const-folding, inlining, DCE, local CSE,
array-length, unboxing, method-to-
static-func
n all optimizations are performed using link-time
information
n is not SSA-based
n to preserve the original code as much as possible
after conversion
n SSA + code generation sometimes cause slowdown
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 22
Optimization Example: Affine Transformation	
n source code:
new Matrix(1, 0, 0, 0, 2, 0).transform(new Point(x, y))	
n generated code:
{x: x + 0 * y, y: 0 * x + 2 * y}	
	
Note: 0 * n cannot be folded since it is equiv. to: isNaN(n) ? NaN : 0
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 23
Future of JSX	
n provide async syntax
n compile the code to callback-passing style
n esp. necessary for node.js
n compile to native?
n for faster performance on PNaCl, asm.js
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 24
Binding JSX to W3C Standards	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 25
Binding JSX to W3C Standards	
n Need to translate W3C IDL to JSX
n for the ease of writing code in JSX
n to use the compiler to detect errors
dom.document.creatElement() // error!
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 26
Binding JSX to W3C standards	
% cat lib/js/js/web.jsx	
(snip)	
	
/** @see http://www.w3.org/TR/DOM-Level-3-Events/ */	
native class Event {	
	
/** @see http://www.w3.org/TR/dom/ */	
function constructor(type : string/*DOMString*/);	
/** @see http://www.w3.org/TR/dom/ */	
function constructor(type : string/*DOMString*/, eventInitDict : EventInit);	
	
/** @see http://www.w3.org/TR/dom/ */	
__readonly__ var type : string/*DOMString*/;	
/** @see http://www.w3.org/TR/dom/ */	
__readonly__ var target : Nullable.<EventTarget>;	
/** @see http://www.w3.org/TR/dom/ */	
__readonly__ var currentTarget : Nullable.<EventTarget>;	
/** @see http://www.w3.org/TR/dom/ */	
static __readonly__ var NONE : number/*unsigned short*/;	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 27
Binding JSX to W3C standards	
n wrote perl scripts to do the translation
n supporting 35 IDLs (358 classes)
n most of those on http://w3.org/
n some from others (Khronos, browser vendors,
etc.)
n we write some IDL as well
n to support vendor-specific defs. (webkitXXX, etc.)
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 28
The Lessons we learned	
n "union types" are not uncommon
n we use variant for now
n so that it could store any type of data
n should we better support disjoint types?
n some types are not narrowed
n HTMLOptionsCollection#item() does not return
HTMLOptionElement
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 29
The Lessons we learned (cont'd)	
n interface definition is lost in JavaScript
n since there is no way in JS to express such ideas
n IDLs on working drafts may have errors
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 30
Conclusion	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 31
Conclusion: it is possible to…	
n use a statically-typed language atop
JavaScript running on web browsers
n to boost productivity and execution speed
n to reduce code footprint
n such approach might become more common as
web evolves
n generate interface defs. from W3C IDLs
automatically
n thanks a lot for providing them!!!!!!	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 32
For more information	
please visit the JSX project page at
jsx.github.io	
Jun 8 2013 JSX - developing a statically-typed programming language for the Web 33

Mais conteúdo relacionado

Mais procurados

Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...
Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...
Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...Nuxeo
 
PHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryPHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryMichael Spector
 
Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyGuillaume Laforge
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...elliando dias
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget coursecrazyaxe
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure JavaAnton Keks
 
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformThomas Wuerthinger
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
Configuring in the Browser, Really!
Configuring in the Browser, Really!Configuring in the Browser, Really!
Configuring in the Browser, Really!Tim Geisler
 
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTThesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTTuononenP
 
.Net framework interview questions
.Net framework interview questions.Net framework interview questions
.Net framework interview questionsMir Majid
 

Mais procurados (14)

Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...
Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...
Creating Large Scale Software Platforms with OSGi and an Extension Point Mode...
 
00_VB_Intro
00_VB_Intro00_VB_Intro
00_VB_Intro
 
PHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success StoryPHP Development Tools 2.0 - Success Story
PHP Development Tools 2.0 - Success Story
 
Practical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in GroovyPractical Domain-Specific Languages in Groovy
Practical Domain-Specific Languages in Groovy
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget course
 
Simple Pure Java
Simple Pure JavaSimple Pure Java
Simple Pure Java
 
Graal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution PlatformGraal VM: Multi-Language Execution Platform
Graal VM: Multi-Language Execution Platform
 
Scripting In Java
Scripting In JavaScripting In Java
Scripting In Java
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Es build presentation
Es build presentationEs build presentation
Es build presentation
 
Configuring in the Browser, Really!
Configuring in the Browser, Really!Configuring in the Browser, Really!
Configuring in the Browser, Really!
 
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDTThesis - LLVM toolchain support as a plug-in for Eclipse CDT
Thesis - LLVM toolchain support as a plug-in for Eclipse CDT
 
.Net framework interview questions
.Net framework interview questions.Net framework interview questions
.Net framework interview questions
 

Semelhante a JSX - developing a statically-typed programming language for the Web

Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right wayYagiz Nizipli
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackdivyapisces
 
Hybrid Application Development
Hybrid Application DevelopmentHybrid Application Development
Hybrid Application DevelopmentYagiz Nizipli
 
Node.js Web Development SEO Expert Bangladesh LTD.pdf
Node.js Web Development  SEO Expert Bangladesh LTD.pdfNode.js Web Development  SEO Expert Bangladesh LTD.pdf
Node.js Web Development SEO Expert Bangladesh LTD.pdfTasnim Jahan
 
State of GeoServer - FOSS4G 2016
State of GeoServer - FOSS4G 2016State of GeoServer - FOSS4G 2016
State of GeoServer - FOSS4G 2016GeoSolutions
 
Node js vs golang -which one is better ?
Node js vs golang -which one is better ?Node js vs golang -which one is better ?
Node js vs golang -which one is better ?ForceBolt
 
.NET vs. Node.js: What to Choose for Web Development
.NET vs. Node.js: What to Choose for Web Development.NET vs. Node.js: What to Choose for Web Development
.NET vs. Node.js: What to Choose for Web DevelopmentDashTechnologiesInc
 
Node.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleDmytro Semenov
 
Understanding Node.js and Django.docx
Understanding Node.js and Django.docxUnderstanding Node.js and Django.docx
Understanding Node.js and Django.docxSavior_Marketing
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptMegha V
 
GWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO ToolsGWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO Toolsbarciszewski
 
Mean Stack for Beginners
Mean Stack for BeginnersMean Stack for Beginners
Mean Stack for BeginnersJEMLI Fathi
 
Java Script recruiting
Java Script recruitingJava Script recruiting
Java Script recruitingIhor Odynets
 
Node.js Web Development .pdf
Node.js Web Development .pdfNode.js Web Development .pdf
Node.js Web Development .pdfAbanti Aazmin
 
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]Leonardo Zanivan
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeWaqqas Jabbar
 

Semelhante a JSX - developing a statically-typed programming language for the Web (20)

Web Development: Making it the right way
Web Development: Making it the right wayWeb Development: Making it the right way
Web Development: Making it the right way
 
Building an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stackBuilding an E-commerce website in MEAN stack
Building an E-commerce website in MEAN stack
 
Hybrid Application Development
Hybrid Application DevelopmentHybrid Application Development
Hybrid Application Development
 
Node.js Web Development SEO Expert Bangladesh LTD.pdf
Node.js Web Development  SEO Expert Bangladesh LTD.pdfNode.js Web Development  SEO Expert Bangladesh LTD.pdf
Node.js Web Development SEO Expert Bangladesh LTD.pdf
 
Dust.js
Dust.jsDust.js
Dust.js
 
MERN PPT
MERN PPTMERN PPT
MERN PPT
 
State of GeoServer - FOSS4G 2016
State of GeoServer - FOSS4G 2016State of GeoServer - FOSS4G 2016
State of GeoServer - FOSS4G 2016
 
Node js vs golang -which one is better ?
Node js vs golang -which one is better ?Node js vs golang -which one is better ?
Node js vs golang -which one is better ?
 
.NET vs. Node.js: What to Choose for Web Development
.NET vs. Node.js: What to Choose for Web Development.NET vs. Node.js: What to Choose for Web Development
.NET vs. Node.js: What to Choose for Web Development
 
Node.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
 
Understanding Node.js and Django.docx
Understanding Node.js and Django.docxUnderstanding Node.js and Django.docx
Understanding Node.js and Django.docx
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
GWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO ToolsGWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO Tools
 
Mean Stack for Beginners
Mean Stack for BeginnersMean Stack for Beginners
Mean Stack for Beginners
 
Java Script recruiting
Java Script recruitingJava Script recruiting
Java Script recruiting
 
Introduction to MERN
Introduction to MERNIntroduction to MERN
Introduction to MERN
 
Node.js Web Development .pdf
Node.js Web Development .pdfNode.js Web Development .pdf
Node.js Web Development .pdf
 
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
JavaOne 2014 - Scalable JavaScript Applications with Project Nashorn [CON6423]
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Explore asp.net core 3.0 features
Explore asp.net core 3.0 featuresExplore asp.net core 3.0 features
Explore asp.net core 3.0 features
 

Mais de Kazuho Oku

HTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときHTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときKazuho Oku
 
QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7Kazuho Oku
 
HTTP/2の課題と将来
HTTP/2の課題と将来HTTP/2の課題と将来
HTTP/2の課題と将来Kazuho Oku
 
TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話Kazuho Oku
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondReorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondKazuho Oku
 
Recent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using rubyRecent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using rubyKazuho Oku
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsivenessKazuho Oku
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsivenessKazuho Oku
 
Developing the fastest HTTP/2 server
Developing the fastest HTTP/2 serverDeveloping the fastest HTTP/2 server
Developing the fastest HTTP/2 serverKazuho Oku
 
TLS & LURK @ IETF 95
TLS & LURK @ IETF 95TLS & LURK @ IETF 95
TLS & LURK @ IETF 95Kazuho Oku
 
HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向Kazuho Oku
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先Kazuho Oku
 
Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Kazuho Oku
 
HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計Kazuho Oku
 
H2O - making the Web faster
H2O - making the Web fasterH2O - making the Web faster
H2O - making the Web fasterKazuho Oku
 
H2O - making HTTP better
H2O - making HTTP betterH2O - making HTTP better
H2O - making HTTP betterKazuho Oku
 
H2O - the optimized HTTP server
H2O - the optimized HTTP serverH2O - the optimized HTTP server
H2O - the optimized HTTP serverKazuho Oku
 
JSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedJSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedKazuho Oku
 
JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法Kazuho Oku
 
JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013Kazuho Oku
 

Mais de Kazuho Oku (20)

HTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないときHTTP/2で 速くなるとき ならないとき
HTTP/2で 速くなるとき ならないとき
 
QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7QUIC標準化動向 〜2017/7
QUIC標準化動向 〜2017/7
 
HTTP/2の課題と将来
HTTP/2の課題と将来HTTP/2の課題と将来
HTTP/2の課題と将来
 
TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話TLS 1.3 と 0-RTT のこわ〜い話
TLS 1.3 と 0-RTT のこわ〜い話
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and BeyondReorganizing Website Architecture for HTTP/2 and Beyond
Reorganizing Website Architecture for HTTP/2 and Beyond
 
Recent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using rubyRecent Advances in HTTP, controlling them using ruby
Recent Advances in HTTP, controlling them using ruby
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsiveness
 
Programming TCP for responsiveness
Programming TCP for responsivenessProgramming TCP for responsiveness
Programming TCP for responsiveness
 
Developing the fastest HTTP/2 server
Developing the fastest HTTP/2 serverDeveloping the fastest HTTP/2 server
Developing the fastest HTTP/2 server
 
TLS & LURK @ IETF 95
TLS & LURK @ IETF 95TLS & LURK @ IETF 95
TLS & LURK @ IETF 95
 
HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向HTTPとサーバ技術の最新動向
HTTPとサーバ技術の最新動向
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
 
Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5Cache aware-server-push in H2O version 1.5
Cache aware-server-push in H2O version 1.5
 
HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計HTTP/2時代のウェブサイト設計
HTTP/2時代のウェブサイト設計
 
H2O - making the Web faster
H2O - making the Web fasterH2O - making the Web faster
H2O - making the Web faster
 
H2O - making HTTP better
H2O - making HTTP betterH2O - making HTTP better
H2O - making HTTP better
 
H2O - the optimized HTTP server
H2O - the optimized HTTP serverH2O - the optimized HTTP server
H2O - the optimized HTTP server
 
JSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons LearnedJSON SQL Injection and the Lessons Learned
JSON SQL Injection and the Lessons Learned
 
JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法JSX 速さの秘密 - 高速なJavaScriptを書く方法
JSX 速さの秘密 - 高速なJavaScriptを書く方法
 
JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013JSX の現在と未来 - Oct 26 2013
JSX の現在と未来 - Oct 26 2013
 

JSX - developing a statically-typed programming language for the Web

  • 1. JSXdeveloping a statically-typed programming language for the Web DeNA Co., Ltd. Kazuho Oku
  • 2. Jun 8 2013 JSX - developing a statically-typed programming language for the Web 2
  • 3. Agenda n JSX n a statically-typed programming language n that gets optimizing-compiled into JavaScript n Binding W3C standards to JSX Jun 8 2013 JSX - developing a statically-typed programming language for the Web 3
  • 4. About me n Name: Kazuho Oku n Career: n Palmscape / Xiino – world's first web browser for Palm OS (1997-2004) n R&D specialist at Cybozu Labs, Inc. (2005-2010) n Japanize – collaborative UI localization service for the Web n Greasemetal – world's first Google Chrome extension n Q4M - message queue plugin for MySQL n used by largest SNSs in Japan n memcached plugin for MySQL n working for DeNA Co., Ltd. (2010-) Jun 8 2013 JSX - developing a statically-typed programming language for the Web 4
  • 5. About DeNA Co., Ltd. n Operator of Mobage n one of the largest mobile gaming platforms in Japan n many games are developed by our partners n games run on web browsers and mobile apps. n we use JavaScript for writing app-based games as well Jun 8 2013 JSX - developing a statically-typed programming language for the Web 5
  • 6. Problems of JavaScript Jun 8 2013 JSX - developing a statically-typed programming language for the Web 6
  • 7. Large-scale Applications using JavaScript n state-of-the-art apps with more than 100k LOC n Kintone (Cybozu) n Cloud web database n similar cases with social game apps. n > 5MB of .js after minified n developed by large team n > 10 members Jun 8 2013 JSX - developing a statically-typed programming language for the Web 7
  • 8. JavaScript – the Good Parts n clear language design with specification n works on any web browser n very fast – thanks to the competition n small and primitive language spec. n prototype-based OO Jun 8 2013 JSX - developing a statically-typed programming language for the Web 8
  • 9. JavaScript – the not-so-good Parts n low productivity n cannot find a bug before execution n great variety in coding style n hard to share the best practice n thus hard to write high-quality code n slow execution speed n compared to native n high memory consumption n slow startup Jun 8 2013 JSX - developing a statically-typed programming language for the Web 9
  • 10. The reason – JavaScript is a dynamic language n error-check only at runtime → negative impact to productivity and quality n adaptive compilation → negative impact on execution speed, startup speed, memory footprint n no heavy compiler optimizations n optimizations possible by JavaScript JIT engines have their limits / overheads → negative impact on execution speed Jun 8 2013 JSX - developing a statically-typed programming language for the Web 10
  • 11. The Solution n Develop a dialect of JavaScript, that… n enforces static types to JavaScript n like ActionScript 3 / EcmaScript 4 n optimize while translating to JavaScript n so that it would run faster than JavaScript! Jun 8 2013 JSX - developing a statically-typed programming language for the Web 11
  • 12. JSX Jun 8 2013 JSX - developing a statically-typed programming language for the Web 12
  • 13. The Goal fo JSX n an excellent programming language for the web browsers n run faster than JavaScript, on any web browser n important for browser-based games on smartphones n higher productivity than JavaScript n easy to learn / maintain n esp. for JavaScript programmers n esp. in medium to large-scale development n help writing high-quality code than in JavaScript Jun 8 2013 JSX - developing a statically-typed programming language for the Web 13
  • 14. Design Principles of JSX n fully statically-typed n detect as many errors as possible at compile-time n leads to higher productivity and better quality n provide optimizing compiler using the type information n expressions and statements are: JavaScript + type annotations n easy to learn n no overhead by conversion to JavaScript n inject helper-code for debugging during compile n Class-based OO Jun 8 2013 JSX - developing a statically-typed programming language for the Web 14
  • 15. The Language class Point { var x = 0; // x is a "number" var y = 0; // y is a "number" function constructor() { } function constructor(x : number, y : number) { this.x = x; this.y = y; } override function toString() : string { return this.x as string + "," + this.y as string; } } Jun 8 2013 JSX - developing a statically-typed programming language for the Web 15
  • 16. Performance Benchmarks n Box2D n convert box2d.js to JSX and measure the fps n iOS 5.0 – 12% speed-up n Android 2.3 – 29% speed-up n  AOBench n  from http://spheresofa.net/blog/?p=757 Jun 8 2013 JSX - developing a statically-typed programming language for the Web 0 0.5 1 1.5 2 JavaScript JSX TypeScript Haxe 処理速度 iOS Android 16
  • 17. Minify Jun 8 2013 JSX - developing a statically-typed programming language for the Web n Minify is safe and more effective thanks to the type information 0" 0.2" 0.4" 0.6" 0.8" 1" 1.2" Total" ngCore"HTML5" JSX" v8bench.jsx" byte%size%of%generated%code(ra2o)% Impact%of%Minifica2on jsx"AArelease" jsx"AArelease"|"uglifyjs" jsx"AArelease"|"esmangle" jsx"AArelease"AAminify" 17
  • 18. Debugging on Chrome Jun 8 2013 JSX - developing a statically-typed programming language for the Web 18
  • 19. Automatic Completion Jun 8 2013 JSX - developing a statically-typed programming language for the Web 19
  • 20. Integrated Test Framework // to run: jsx --test hello.jsx import "test-case.jsx"; class _Test extends TestCase { function test1() :void { this.expect("hello").toBe("hello"); this.expect("world").toBe("world"); } function test2() :void { this.expect(42).toBe(42); } } Jun 8 2013 JSX - developing a statically-typed programming language for the Web 20
  • 21. Profiler n works on any runtime with XHR support Jun 8 2013 JSX - developing a statically-typed programming language for the Web 21
  • 22. Supported Optimization Methods n const-folding, inlining, DCE, local CSE, array-length, unboxing, method-to- static-func n all optimizations are performed using link-time information n is not SSA-based n to preserve the original code as much as possible after conversion n SSA + code generation sometimes cause slowdown Jun 8 2013 JSX - developing a statically-typed programming language for the Web 22
  • 23. Optimization Example: Affine Transformation n source code: new Matrix(1, 0, 0, 0, 2, 0).transform(new Point(x, y)) n generated code: {x: x + 0 * y, y: 0 * x + 2 * y} Note: 0 * n cannot be folded since it is equiv. to: isNaN(n) ? NaN : 0 Jun 8 2013 JSX - developing a statically-typed programming language for the Web 23
  • 24. Future of JSX n provide async syntax n compile the code to callback-passing style n esp. necessary for node.js n compile to native? n for faster performance on PNaCl, asm.js Jun 8 2013 JSX - developing a statically-typed programming language for the Web 24
  • 25. Binding JSX to W3C Standards Jun 8 2013 JSX - developing a statically-typed programming language for the Web 25
  • 26. Binding JSX to W3C Standards n Need to translate W3C IDL to JSX n for the ease of writing code in JSX n to use the compiler to detect errors dom.document.creatElement() // error! Jun 8 2013 JSX - developing a statically-typed programming language for the Web 26
  • 27. Binding JSX to W3C standards % cat lib/js/js/web.jsx (snip) /** @see http://www.w3.org/TR/DOM-Level-3-Events/ */ native class Event { /** @see http://www.w3.org/TR/dom/ */ function constructor(type : string/*DOMString*/); /** @see http://www.w3.org/TR/dom/ */ function constructor(type : string/*DOMString*/, eventInitDict : EventInit); /** @see http://www.w3.org/TR/dom/ */ __readonly__ var type : string/*DOMString*/; /** @see http://www.w3.org/TR/dom/ */ __readonly__ var target : Nullable.<EventTarget>; /** @see http://www.w3.org/TR/dom/ */ __readonly__ var currentTarget : Nullable.<EventTarget>; /** @see http://www.w3.org/TR/dom/ */ static __readonly__ var NONE : number/*unsigned short*/; Jun 8 2013 JSX - developing a statically-typed programming language for the Web 27
  • 28. Binding JSX to W3C standards n wrote perl scripts to do the translation n supporting 35 IDLs (358 classes) n most of those on http://w3.org/ n some from others (Khronos, browser vendors, etc.) n we write some IDL as well n to support vendor-specific defs. (webkitXXX, etc.) Jun 8 2013 JSX - developing a statically-typed programming language for the Web 28
  • 29. The Lessons we learned n "union types" are not uncommon n we use variant for now n so that it could store any type of data n should we better support disjoint types? n some types are not narrowed n HTMLOptionsCollection#item() does not return HTMLOptionElement Jun 8 2013 JSX - developing a statically-typed programming language for the Web 29
  • 30. The Lessons we learned (cont'd) n interface definition is lost in JavaScript n since there is no way in JS to express such ideas n IDLs on working drafts may have errors Jun 8 2013 JSX - developing a statically-typed programming language for the Web 30
  • 31. Conclusion Jun 8 2013 JSX - developing a statically-typed programming language for the Web 31
  • 32. Conclusion: it is possible to… n use a statically-typed language atop JavaScript running on web browsers n to boost productivity and execution speed n to reduce code footprint n such approach might become more common as web evolves n generate interface defs. from W3C IDLs automatically n thanks a lot for providing them!!!!!! Jun 8 2013 JSX - developing a statically-typed programming language for the Web 32
  • 33. For more information please visit the JSX project page at jsx.github.io Jun 8 2013 JSX - developing a statically-typed programming language for the Web 33