SlideShare a Scribd company logo
Dart 1.1
Outline


最近の様子 (Dart VM と dart2js)



Dart VM の特長



Java と比較
2014/02/09 Go 弱の会 + Dart
nothingcosmos <nothingcosmos@gmail.com>
最近の様子 (Dart VM)


ARM 対応完了。 Android+ARM 向けにクロスビルド可能
x86/x64/arm/mips Linux/Windows/MacOS/Android



デバッガ連携の強化や、 signal handler 対応、 vm の profiler の強化



vm­service の強化 (socket 接続して json で vm 内部を参照できる機能 )



computer language benchmark games の single threading なら
go とほぼ等速、 Java より 20% ~ 50% 遅いくらいのはず。
※手元では benchmark games の公表値より Dart と Java の差は小さい。
※multi threading では比べるな、、 go は parallel/concurrent 向けだし、
※JVM(HotSpot) は MultiThreading 特化だから。。
vm­service stacktrace

dart –enable-vm-service xxx.dart
localhost:8181 で stacktrace や profile や各種統計情報を参照可能
最近の様子 (dart2js)


dart2js は Dart から JavaScript に変換する。



高速化中、手書きの JavaScript V8 と等速、ちょい速いくらい。



Dart 1.0 より、ベンチマークの Richard が 25% アップ。
http://news.dartlang.org/2014/01/dart­11­features­up­to­25­faster.html



Tracer がすごく速くなった理由は、 SsaLoadElimination の追加
type_graph_inferrer の追加 ( 手続き間で型推論を収束するまで繰り返す )



こんな感じでいろいろと最適化を追加している。



ベンチマークは Octane  や Dromaeo や Box2D っぽい。
Dart2js Tracer Benchmark
Dart VM の特長
ここから VM の雑学


Dart VM Architecture



Isolate



Snapshot



Message passing



Event Driven & Zone



Optional Typing & Generics



Checked Mode
Dart VM Architecture


JVM(HotSpot) の特長
MulthThreading 特化。 TLAB/Lock の IR が豊富 / 冗長な Lock/Unlock 除去。
スループット重視、 SEDA 。ソフトウェアリアルタイム性重視は
G1GC/Shenandoh 。



Erlang VM(BEAM) の特長
低レイテンシ重視。インタプリタ +HiPE 。 shared nothing で Actor モデル。
SMP 対応版は起動時に、 Queue 処理 8thread と async 処理 8Thread 。
ErlProcess は VM 内で Switch 可能。 GC は ErlProcess 単位でコントロール可能。



Dart VM の特長
スループット重視、 JIT Compile/GC も完全に blocking 。
GC は Isolate 単位でコントロール可能。
shared nothing で MessagePassing 、 Async でも 1Thread で EventLoop 。
Isolate を複数起動して並列実行。 1Thread なので Lock/Unlock はない。
Dart

Dart VM Architecture
Dart の世界
Debugger で
追える境界

sdk/lib/io

NativeSymbol
C++/Asm
OS/Kernel

sdk/lib
patch_class

VM の境界
Native Extensions
シンボルを定義

runtime/lib/*.cc
runtime/bin/*.cc
IO_NATIVES

BOOTSTRAP_
NATIVES

runtime/lib
runtime/bin
I/O や Network
を非同期に実行

runtime/platform

runtime/
include

runtime/vm
runtime/vm/os

OS(Linux, Windows,
MacOS, Android)

ISA(arch)
ia32/x64/arm/mips

VM が担当する
計算やリソース管理
VM Runtime 部分を拡大
BOOTSTRAP_NATIVES
Dart レイヤから C++ への binding/Native Extentions

JITCompiler のみ
インタプリタ無し

intrinsifier/runtime_entry

compiler

GC
Heap に対して
NewGen/OldGen

port_map
Message
Passing は
port 経由

dart
context

object
pool/code
heap
isolate
thread_pool
OS の Process

runtime/
stubs
Dart_Api
include
Dart VM Isolate
Isolate 横断

BOOTSTRAP_NATIVES
Dart レイヤから C++ への binding/Native Extentions
intrinsifier/runtime_entry
compiler

GC
Isolate 単位に
独立

port_map

dart
context

object
pool/code
heap
isolate
thread_pool
OS の Process

VM の共有リソース

runtime
stubs
Dart_Api
include
Isolate  Spawn
intrinsifier/runtime_entry
runtime
stubs

dart
context
object
pool/code

compiler
GC

heap

runtime
stubs

dart
context
object
pool/code

compiler
GC

heap

isolate
Thread
port_map

isolate 間は port 経由で
message passing

Spawn した
Isolate

Dart_Api
include

isolate
Lock は不要
独立して実行

Thread

thread_pool
OS の Process

共有リソースでは Lock するが、
非常に少ない。
Dart Snapshot


Dart VM の object の serialize/deserialize 機能
圧縮率と速度優先
アーキテクチャ非互換 (x86­x64­ARM 間の相互変換は不可能 )



起動の高速化



MessagePassing の際の serialize/deserialize にも使用する。
serialize した Dart object を port 経由で送受信する。



Snapshot の対象 == MessagePassing 可能な object の種類
大体 JSON と同じだけど、追加で VM の内部 object も対象。
VM 起動の高速化


Dart VM は make の際に、 2 回 build を行う。
1 回目は dart_no_snapshot を build し、 SDK の core を読み込み起動。
core の dart src を scan し、 snapshot 、 snapshot_buffer[] に書き出し。



2 回目で snapshot_buffer[] を取り込んで dart を build する。 +400kbyte
dart は Core の I/O と Scan を skip できるので、起動時間が短縮できる。
­­time­bootstrap オプションで比較可能。



bootstrap が短縮、 100,000micros ­> 100micros
bootstrap の短縮
fibo(40) の実行時間 (ms)

130ms
540
dart_no_snapshot

410
fibo
time

20ms

起動時のオー
430
バーヘッドが 1/6
scan が 100ms
410
から 0.1ms に

dart

0

100

200

300

400

500

600
Isolate 間の MessagePassing
SnapshotWriter
serialize

SnapshotReader
deserialize

Isolate
Message
HandlerTask

Isolate
Message
Handler

Message
Handler

Thread

Message
HandlerTask
Thread

port_map
相手の Isolate に
message を送る
ReceivePort を
全部 mapping してある
Isolate の StartUp
main が終わったら、
MessageHandler で
EventLoop
Task が
Thread を生成
1 個だけ

dart main から
起動

Isolate
Message
HandlerTask

Message
Handler

Thread
thread
pool

async task が
残っている限り
仕事し続ける。
Message
Receive

port_map

Unhandled exception:
type 'double' is not a subtype of type 'int' of 'num'.
#0
func (file:///syntax/lib/diff/future.dart:28:13)
#1
main (file:///syntax/lib/diff/future.dart:33:7)
#2
_startIsolate.isolateStartHandler (dart:isolate-patch/isolate_patch.dart:216)
#3
_RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:115)
MessageHandler and EventLoop


Dart は main から始まる script を実行した後
に、
Message Handler のループを実行する。



main が終了後、
async の非同期処理を実行する。
EventLoop And Zone


Zone は RootZone から parent が fork して
木構造でつながる。

zone



scheduleMicrotask で順次実行
Zone の木構造に応じて 1thread で順番に実行

zone
current_zone
zone

zone
Dart VM の特長


Dart VM Architecture



Isolate



Snapshot



Message passing



Event Driven & Zone



Optional Typing & Generics



Checked Mode
Dart Optional Typing


Dart には production mode と checked mode がある。



Dart には 3 つのフェーズがある。




compile フェーズ。 script 実行前の jit compile 時に error/warning 検出





analyzer フェーズ。 IDE による error/warning の検出
runtime フェーズ。実行時の型情報を validation する。

checked mode では、 compile フェーズで型エラー /warning を無視しない。
compile 時に型情報の validation 命令を挿入し、実行時に assert する。



Dart の型は、 type annotation による validation と割り切っている。
validation のタイミングは上記 3 つ。 runtime に影響を与えない。
Dart Optional Typing


Dart の型の違反は、基本的に warning 扱い



何が error で何が warning かは、他の言語と比較すると結構曖昧かも。
Breaking on exception:
type 'double' is not a subtype of type 'int' of 'num'.

int sum = 100 + 100.0;

int num = 100.0;

IDE/ コンパイル時に warning と分かるし、
binaryoperator(+) の 2 引数の validation 命令を
JIT コンパイル時に挿入する。
実行時に validation されて warning

こちらは = の assign に validation 版の命令を
JIT コンパイル時に挿入する。
実行時に validation されて warning

Breaking on exception:
type 'double' is not a subtype of type 'int' of 'num'.
Dart Generics


Class の Reified Generics のみ ( 型パラメータを保存する領域あり )
Generics を使用した場合のみ、 Class のインスタンスを new する際に、
型パラメータを保存する命令を挿入する。
TypeArguments っていう IR が存在する。



Method generics は存在しない。



型パラメータを参照するのは、 checked mode のみ。
Generics の型パラメータも validation のみ。
Java と Collection を比較


新しめの Java のライブラリと API を比較してみる。



Guava(Google) Stopwatch



Guava(Google) ListenableFuture



Java8 Stream



Presto(Facebook) IterableTransformer



Dart の Stream
Stopwatch の比較


Java guava の Stopwatch と比較
Future の比較


Java guava の ListenableFuture と比較

Java は thread を使って parallel 実行
Dart の async/future は EventLoop で処理
Stream の比較


Java8 の stream と比較 (http://d.hatena.ne.jp/nowokay/20130504)

Dart は Iterable
lexical scope と closure があるので書きやすいと思う。
Iterable の比較
Java presto の IterableTransformer と比較
Dart の Stream


Dart の Stream は基本的に async で実行。 main 終了後の EvetLoop の実行待ち
StreamController 作って add で流し込んでいく、 listen で受け取る事が多い。



Stream を pipe でつないだり broadcast で分岐できる。

More Related Content

What's hot (12)

AVX命令を用いたLJの力計算のSIMD化
AVX命令を用いたLJの力計算のSIMD化AVX命令を用いたLJの力計算のSIMD化
AVX命令を用いたLJの力計算のSIMD化
Hiroshi Watanabe
 
EthernetやCPUなどの話
EthernetやCPUなどの話EthernetやCPUなどの話
EthernetやCPUなどの話
Takanori Sejima
 
OpenStackでつくる開発環境と外道塾
OpenStackでつくる開発環境と外道塾OpenStackでつくる開発環境と外道塾
OpenStackでつくる開発環境と外道塾
外道 父
 
1 usermod廃止のチャンス到来
1 usermod廃止のチャンス到来1 usermod廃止のチャンス到来
1 usermod廃止のチャンス到来
IBMソリューション
 
x86-64/Linuxに独自メモリ空間を勝手増設
x86-64/Linuxに独自メモリ空間を勝手増設x86-64/Linuxに独自メモリ空間を勝手増設
x86-64/Linuxに独自メモリ空間を勝手増設
Minoru Nakamura
 
SakuRuby SakuraJam-Ver.3.10 の説明資料です
SakuRuby SakuraJam-Ver.3.10 の説明資料ですSakuRuby SakuraJam-Ver.3.10 の説明資料です
SakuRuby SakuraJam-Ver.3.10 の説明資料です
三七男 山本
 
マイグレーション教授のワンポイント・アドバイス
マイグレーション教授のワンポイント・アドバイスマイグレーション教授のワンポイント・アドバイス
マイグレーション教授のワンポイント・アドバイス
IBMソリューション
 
短距離古典分子動力学計算の 高速化と大規模並列化
短距離古典分子動力学計算の 高速化と大規模並列化短距離古典分子動力学計算の 高速化と大規模並列化
短距離古典分子動力学計算の 高速化と大規模並列化
Hiroshi Watanabe
 
AVX命令を用いたLJの力計算のSIMD化
AVX命令を用いたLJの力計算のSIMD化AVX命令を用いたLJの力計算のSIMD化
AVX命令を用いたLJの力計算のSIMD化
Hiroshi Watanabe
 
EthernetやCPUなどの話
EthernetやCPUなどの話EthernetやCPUなどの話
EthernetやCPUなどの話
Takanori Sejima
 
OpenStackでつくる開発環境と外道塾
OpenStackでつくる開発環境と外道塾OpenStackでつくる開発環境と外道塾
OpenStackでつくる開発環境と外道塾
外道 父
 
x86-64/Linuxに独自メモリ空間を勝手増設
x86-64/Linuxに独自メモリ空間を勝手増設x86-64/Linuxに独自メモリ空間を勝手増設
x86-64/Linuxに独自メモリ空間を勝手増設
Minoru Nakamura
 
SakuRuby SakuraJam-Ver.3.10 の説明資料です
SakuRuby SakuraJam-Ver.3.10 の説明資料ですSakuRuby SakuraJam-Ver.3.10 の説明資料です
SakuRuby SakuraJam-Ver.3.10 の説明資料です
三七男 山本
 
マイグレーション教授のワンポイント・アドバイス
マイグレーション教授のワンポイント・アドバイスマイグレーション教授のワンポイント・アドバイス
マイグレーション教授のワンポイント・アドバイス
IBMソリューション
 
短距離古典分子動力学計算の 高速化と大規模並列化
短距離古典分子動力学計算の 高速化と大規模並列化短距離古典分子動力学計算の 高速化と大規模並列化
短距離古典分子動力学計算の 高速化と大規模並列化
Hiroshi Watanabe
 

Viewers also liked (20)

LeaderSupportProject20110418
LeaderSupportProject20110418LeaderSupportProject20110418
LeaderSupportProject20110418
Yuichi Morito
 
E learning-basic guidelines to develop multimedia learning
E learning-basic guidelines to develop multimedia learningE learning-basic guidelines to develop multimedia learning
E learning-basic guidelines to develop multimedia learning
Dimas Prasetyo
 
new Year
new Yearnew Year
new Year
87honey
 
IT ALYAN
IT ALYANIT ALYAN
IT ALYAN
SIG-Saudi Investment Group
 
Struds 2010(aug)
Struds 2010(aug)Struds 2010(aug)
Struds 2010(aug)
SoftTechengr
 
Coursework evaluation q 4
Coursework evaluation q 4Coursework evaluation q 4
Coursework evaluation q 4
salesianas2011
 
Pm 75 nine dragons
Pm 75 nine dragonsPm 75 nine dragons
Pm 75 nine dragons
Umberto Pacheco
 
Fly over europe
Fly over europeFly over europe
Fly over europe
Umberto Pacheco
 

Similar to Dart 1.1 (20)

2014 dart flight school in Tokyo
2014 dart flight school in Tokyo2014 dart flight school in Tokyo
2014 dart flight school in Tokyo
nothingcosmos
 
Rubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつりRubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつり
Yuya Rin
 
Dart VM Performance
Dart VM PerformanceDart VM Performance
Dart VM Performance
nothingcosmos
 
ceph acceleration and storage architecture
ceph acceleration and storage architectureceph acceleration and storage architecture
ceph acceleration and storage architecture
Yuki Kitajima
 
Azure vm の可用性を見直そう
Azure vm の可用性を見直そうAzure vm の可用性を見直そう
Azure vm の可用性を見直そう
ShuheiUda
 
ホット・トピック・セミナー「Metro」
ホット・トピック・セミナー「Metro」ホット・トピック・セミナー「Metro」
ホット・トピック・セミナー「Metro」
Kohsuke Kawaguchi
 
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
VirtualTech Japan Inc.
 
OSC 2012 Hokkaido でのプレゼン資料
OSC 2012 Hokkaido でのプレゼン資料OSC 2012 Hokkaido でのプレゼン資料
OSC 2012 Hokkaido でのプレゼン資料
Shin-ya Koga
 
2014 dart flight school in Tokyo
2014 dart flight school in Tokyo2014 dart flight school in Tokyo
2014 dart flight school in Tokyo
nothingcosmos
 
Rubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつりRubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつり
Yuya Rin
 
ceph acceleration and storage architecture
ceph acceleration and storage architectureceph acceleration and storage architecture
ceph acceleration and storage architecture
Yuki Kitajima
 
Azure vm の可用性を見直そう
Azure vm の可用性を見直そうAzure vm の可用性を見直そう
Azure vm の可用性を見直そう
ShuheiUda
 
ホット・トピック・セミナー「Metro」
ホット・トピック・セミナー「Metro」ホット・トピック・セミナー「Metro」
ホット・トピック・セミナー「Metro」
Kohsuke Kawaguchi
 
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
知っておくべきCephのIOアクセラレーション技術とその活用方法 - OpenStack最新情報セミナー 2015年9月
VirtualTech Japan Inc.
 
OSC 2012 Hokkaido でのプレゼン資料
OSC 2012 Hokkaido でのプレゼン資料OSC 2012 Hokkaido でのプレゼン資料
OSC 2012 Hokkaido でのプレゼン資料
Shin-ya Koga
 

More from nothingcosmos (6)

Source Code of Dart
Source Code of DartSource Code of Dart
Source Code of Dart
nothingcosmos
 
DartVM on Android
DartVM on AndroidDartVM on Android
DartVM on Android
nothingcosmos
 
Adaptive optimization of JIT compiler
Adaptive optimization of JIT compilerAdaptive optimization of JIT compiler
Adaptive optimization of JIT compiler
nothingcosmos
 
OpenJDK HotSpot C1Compiler Overview
OpenJDK HotSpot C1Compiler OverviewOpenJDK HotSpot C1Compiler Overview
OpenJDK HotSpot C1Compiler Overview
nothingcosmos
 
X86opti01 nothingcosmos
X86opti01 nothingcosmosX86opti01 nothingcosmos
X86opti01 nothingcosmos
nothingcosmos
 
LLVM overview 20110122
LLVM overview 20110122LLVM overview 20110122
LLVM overview 20110122
nothingcosmos
 
Adaptive optimization of JIT compiler
Adaptive optimization of JIT compilerAdaptive optimization of JIT compiler
Adaptive optimization of JIT compiler
nothingcosmos
 
OpenJDK HotSpot C1Compiler Overview
OpenJDK HotSpot C1Compiler OverviewOpenJDK HotSpot C1Compiler Overview
OpenJDK HotSpot C1Compiler Overview
nothingcosmos
 
X86opti01 nothingcosmos
X86opti01 nothingcosmosX86opti01 nothingcosmos
X86opti01 nothingcosmos
nothingcosmos
 
LLVM overview 20110122
LLVM overview 20110122LLVM overview 20110122
LLVM overview 20110122
nothingcosmos
 

Dart 1.1