SlideShare a Scribd company logo
1 of 16
Download to read offline
オブジェクトのカタチ




      MORITA Hajime <omo@dodgson.org>
                           2008/11/16
あらすじ




    TraceMonkey の
 プロパティアクセスは
      爆速だぜ


       http://www.flickr.com/photos/dnorman/2726761770/
Property Accesses
// read
var a = foo.x;
// write
foo.y = b;
// call
foo.z();
ライバルのニュース
ライバルのひみつ




●   Hidden class というのがあるらしい
ライバルのコメント欄




CTO of Mozilla Corp.
コメント欄の CTO 曰く ...




●   Hidden class は別にすごくないぜ
●   SpiderMonkey には
    Shape based polymorphic caching てのが
    あるんだぜ
Shape based polymorphic caching
ある JS コードの JIT 結果 ( 機械語 ) が
●   プロパティの検索結果をキャッシュ
     –   次回以降のアクセスで使う
●   オブジェクトの shape が同じなら
    キャッシュにヒット
●   ヒットすると高速にプロパティアクセス

ぎもん
● 検索結果ってなに?


● Shape ってなに?
実行イメージ ( キャッシュ前 )
                                     JavaScript
var a = point.x;


                                初回実行 (JIT 前 )
// 検索処理 : 遅い
ScopeProperty* point_x_sp
   = point->scope->findScopeProperty(quot;xquot;);
// 配列アクセス : 速い
Object* a = point->dslot[point_x_sp->slot];
// 検索結果 = ScopeProperty(slot) をキャッシュ
// shape がキー
ctx->update_cache(point->scope->shape,
                  point_x_sp,
                  __FILE__, __LINE__);
実行イメージ ( キャッシュ後 )
                                JIT されたコード
// キャッシュした shape と一致するか ?
if (POINT_SHAPE != point->scope->shape)
   goto cache_miss; // 一致しなかった : ハズレ
ScopeProperty* sprop
   = obj->scope->findScopeProperty(quot;xquot;);
Object* a = obj->dslot[sprop->slot];
// shape が一致した :
// キャッシュした添字で配列アクセス . 検索ナシ .
//                    → 爆速 !
Object* a = point->dslot[POINT_X_SP_SLOT];
Shape?
オブジェクトのもつプロパティの種類のこと
● オブジェクト A と B が


    –   同じ名前で
    –   同じ属性のプロパティを
    –   同じ順番に
    –   同じ数だけ持っていたら
●   A と B は同じ shape をもつ
●   細かい面倒は色々あるけど割愛 
OK: 同じ
function Point(x, y) {
    this.x = x; this.y = y;
}
function Location(x, y) {
    this.x = x; this.y = y;
}
var a = new Point(10, 20);
var b = new Location(30, 40);
NG: 違う数
function Point(x, y) {
    this.x = x; this.y = y;
}
function Point3D(x, y, z) {
    this.x = x; this.y = y; this.z = z;
}
var a = new Point(10, 20);
var b = new Point3D(30, 40, 50);
NG: 違う順序
function Point(x, y) {
    this.x = x; this.y = y;
}
function PointYX(x, y) {
    this.y = y; this.x = x;
}
var a = new Point(10, 20);
var b = new PointYX(30, 40);
ベンチマーク
...
function manhattan_length(p) { return p.x + p.y; }

var P0 = Point;
var P1 = Location; // Point, PointYX, Point3D, ..
function hello() {
  var arr = [new P0(10,20), new P1(30,40)];
  for (var i=0; i<10000000; ++i) {
     for (var j=0; j<2; ++j) {
       manhattan_length(arr[j]);
     }
  }
}

hello();
結果 (shorter is faster)
Location



PointYX
                                                            JIT
                                                            No-JIT

Point3D


           0       2   4   6   8   10   12   14   16   18
●   Shape が同じだと速い
●   Shape が違うと遅い
●   JIT なしだと大差ない
●
    ベンチマーク結果はブランチのものです
               –   (Shape 違いで JIT の方が遅いのはたぶんバグ )

More Related Content

What's hot

Identity Technology Trend Overview, February 2009
Identity Technology Trend Overview, February 2009Identity Technology Trend Overview, February 2009
Identity Technology Trend Overview, February 2009Tatsuo Kudo
 
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理Shinya Miyazaki
 
【12-C-5】 自律型移動ロボットのソフトウェア技術
【12-C-5】 自律型移動ロボットのソフトウェア技術【12-C-5】 自律型移動ロボットのソフトウェア技術
【12-C-5】 自律型移動ロボットのソフトウェア技術devsumi2009
 
寒霜引擎地形渲染使用过程化着色
寒霜引擎地形渲染使用过程化着色寒霜引擎地形渲染使用过程化着色
寒霜引擎地形渲染使用过程化着色zXr0
 
jant aur jant walo ki jalalk
jant aur jant walo ki jalalk jant aur jant walo ki jalalk
jant aur jant walo ki jalalk ghulamenabi786
 
Letter of Recommendations Fanscape (1)
Letter of Recommendations Fanscape (1)Letter of Recommendations Fanscape (1)
Letter of Recommendations Fanscape (1)Gina Santucci
 
1 b1499reqts
1 b1499reqts1 b1499reqts
1 b1499reqtsDanu Dani
 

What's hot (8)

Identity Technology Trend Overview, February 2009
Identity Technology Trend Overview, February 2009Identity Technology Trend Overview, February 2009
Identity Technology Trend Overview, February 2009
 
ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理ブラウザでMap Reduce風味の並列分散処理
ブラウザでMap Reduce風味の並列分散処理
 
【12-C-5】 自律型移動ロボットのソフトウェア技術
【12-C-5】 自律型移動ロボットのソフトウェア技術【12-C-5】 自律型移動ロボットのソフトウェア技術
【12-C-5】 自律型移動ロボットのソフトウェア技術
 
寒霜引擎地形渲染使用过程化着色
寒霜引擎地形渲染使用过程化着色寒霜引擎地形渲染使用过程化着色
寒霜引擎地形渲染使用过程化着色
 
Eca em quadrinhos_turma_da_monica
Eca em quadrinhos_turma_da_monicaEca em quadrinhos_turma_da_monica
Eca em quadrinhos_turma_da_monica
 
jant aur jant walo ki jalalk
jant aur jant walo ki jalalk jant aur jant walo ki jalalk
jant aur jant walo ki jalalk
 
Letter of Recommendations Fanscape (1)
Letter of Recommendations Fanscape (1)Letter of Recommendations Fanscape (1)
Letter of Recommendations Fanscape (1)
 
1 b1499reqts
1 b1499reqts1 b1499reqts
1 b1499reqts
 

Similar to object-shapes

Sc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaSc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaToshihiro Nakamura
 
Where20 2009report
Where20 2009reportWhere20 2009report
Where20 2009reportToru Mori
 
アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—Fumihiko Kinoshita
 
Webken 03: Project Design for Optimaizing User Experience
Webken 03: Project Design for Optimaizing User ExperienceWebken 03: Project Design for Optimaizing User Experience
Webken 03: Project Design for Optimaizing User ExperienceNobuya Sato
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説mochiko AsTech
 
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTracterada
 
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編mochiko AsTech
 
Ohp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 MojiretsuOhp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 Mojiretsusesejun
 
文献紹介:Semantic-based information retrieval in support of concept design.
文献紹介:Semantic-based information retrieval in support of concept design.文献紹介:Semantic-based information retrieval in support of concept design.
文献紹介:Semantic-based information retrieval in support of concept design.Shin Sano
 
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーションYuya Yamaki
 
QM-076-六標準差管理方法的解題邏輯與策略
QM-076-六標準差管理方法的解題邏輯與策略QM-076-六標準差管理方法的解題邏輯與策略
QM-076-六標準差管理方法的解題邏輯與策略handbook
 
Open Source Type Pad Mobile
Open Source Type Pad MobileOpen Source Type Pad Mobile
Open Source Type Pad MobileHiroshi Sakai
 
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法devsumi2009
 
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」devsumi2009
 
20090522 Candycane
20090522 Candycane20090522 Candycane
20090522 CandycaneYusuke Ando
 

Similar to object-shapes (20)

Sc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク DomaSc2009autumn 次世代Daoフレームワーク Doma
Sc2009autumn 次世代Daoフレームワーク Doma
 
Where20 2009report
Where20 2009reportWhere20 2009report
Where20 2009report
 
アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—
 
dRuby
dRubydRuby
dRuby
 
Webken 03: Project Design for Optimaizing User Experience
Webken 03: Project Design for Optimaizing User ExperienceWebken 03: Project Design for Optimaizing User Experience
Webken 03: Project Design for Optimaizing User Experience
 
Reloaded
ReloadedReloaded
Reloaded
 
Programming JNI
Programming JNIProgramming JNI
Programming JNI
 
20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説20090418 イケテルRails勉強会 第2部Air編 解説
20090418 イケテルRails勉強会 第2部Air編 解説
 
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
 
20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編20090418 イケテルRails勉強会 第2部Air編
20090418 イケテルRails勉強会 第2部Air編
 
Ohp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 MojiretsuOhp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 Mojiretsu
 
文献紹介:Semantic-based information retrieval in support of concept design.
文献紹介:Semantic-based information retrieval in support of concept design.文献紹介:Semantic-based information retrieval in support of concept design.
文献紹介:Semantic-based information retrieval in support of concept design.
 
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション
【13 C 2】デベロッパーに贈る!M-V-VMパターンで造るWPFアプリケーション
 
sigfpai73-kaji
sigfpai73-kajisigfpai73-kaji
sigfpai73-kaji
 
QM-076-六標準差管理方法的解題邏輯與策略
QM-076-六標準差管理方法的解題邏輯與策略QM-076-六標準差管理方法的解題邏輯與策略
QM-076-六標準差管理方法的解題邏輯與策略
 
Open Source Type Pad Mobile
Open Source Type Pad MobileOpen Source Type Pad Mobile
Open Source Type Pad Mobile
 
Green IT
Green ITGreen IT
Green IT
 
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
【12-D-6】 Silverlight によるハイグレードなLOB/BI実現のためのコンポーネント活用法
 
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
【13-C-4】 「もう業務はとまらない!オフライン機能を使った業務アプリケーションの実例と最新 Curl 情報」
 
20090522 Candycane
20090522 Candycane20090522 Candycane
20090522 Candycane
 

More from Hajime Morrita

How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHajime Morrita
 
Binaries Are Not Only Output
Binaries Are Not Only OutputBinaries Are Not Only Output
Binaries Are Not Only OutputHajime Morrita
 

More from Hajime Morrita (7)

On Web Browsers
On Web BrowsersOn Web Browsers
On Web Browsers
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTree
 
Binaries Are Not Only Output
Binaries Are Not Only OutputBinaries Are Not Only Output
Binaries Are Not Only Output
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
clang-intro
clang-introclang-intro
clang-intro
 
devsummit2009js
devsummit2009jsdevsummit2009js
devsummit2009js
 

Recently uploaded

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

object-shapes

  • 1. オブジェクトのカタチ MORITA Hajime <omo@dodgson.org> 2008/11/16
  • 2. あらすじ   TraceMonkey の プロパティアクセスは 爆速だぜ http://www.flickr.com/photos/dnorman/2726761770/
  • 3. Property Accesses // read var a = foo.x; // write foo.y = b; // call foo.z();
  • 5. ライバルのひみつ ● Hidden class というのがあるらしい
  • 7. コメント欄の CTO 曰く ... ● Hidden class は別にすごくないぜ ● SpiderMonkey には Shape based polymorphic caching てのが あるんだぜ
  • 8. Shape based polymorphic caching ある JS コードの JIT 結果 ( 機械語 ) が ● プロパティの検索結果をキャッシュ – 次回以降のアクセスで使う ● オブジェクトの shape が同じなら キャッシュにヒット ● ヒットすると高速にプロパティアクセス ぎもん ● 検索結果ってなに? ● Shape ってなに?
  • 9. 実行イメージ ( キャッシュ前 ) JavaScript var a = point.x; 初回実行 (JIT 前 ) // 検索処理 : 遅い ScopeProperty* point_x_sp = point->scope->findScopeProperty(quot;xquot;); // 配列アクセス : 速い Object* a = point->dslot[point_x_sp->slot]; // 検索結果 = ScopeProperty(slot) をキャッシュ // shape がキー ctx->update_cache(point->scope->shape, point_x_sp, __FILE__, __LINE__);
  • 10. 実行イメージ ( キャッシュ後 ) JIT されたコード // キャッシュした shape と一致するか ? if (POINT_SHAPE != point->scope->shape) goto cache_miss; // 一致しなかった : ハズレ ScopeProperty* sprop = obj->scope->findScopeProperty(quot;xquot;); Object* a = obj->dslot[sprop->slot]; // shape が一致した : // キャッシュした添字で配列アクセス . 検索ナシ . // → 爆速 ! Object* a = point->dslot[POINT_X_SP_SLOT];
  • 11. Shape? オブジェクトのもつプロパティの種類のこと ● オブジェクト A と B が – 同じ名前で – 同じ属性のプロパティを – 同じ順番に – 同じ数だけ持っていたら ● A と B は同じ shape をもつ ● 細かい面倒は色々あるけど割愛 
  • 12. OK: 同じ function Point(x, y) { this.x = x; this.y = y; } function Location(x, y) { this.x = x; this.y = y; } var a = new Point(10, 20); var b = new Location(30, 40);
  • 13. NG: 違う数 function Point(x, y) { this.x = x; this.y = y; } function Point3D(x, y, z) { this.x = x; this.y = y; this.z = z; } var a = new Point(10, 20); var b = new Point3D(30, 40, 50);
  • 14. NG: 違う順序 function Point(x, y) { this.x = x; this.y = y; } function PointYX(x, y) { this.y = y; this.x = x; } var a = new Point(10, 20); var b = new PointYX(30, 40);
  • 15. ベンチマーク ... function manhattan_length(p) { return p.x + p.y; } var P0 = Point; var P1 = Location; // Point, PointYX, Point3D, .. function hello() { var arr = [new P0(10,20), new P1(30,40)]; for (var i=0; i<10000000; ++i) { for (var j=0; j<2; ++j) { manhattan_length(arr[j]); } } } hello();
  • 16. 結果 (shorter is faster) Location PointYX JIT No-JIT Point3D 0 2 4 6 8 10 12 14 16 18 ● Shape が同じだと速い ● Shape が違うと遅い ● JIT なしだと大差ない ● ベンチマーク結果はブランチのものです – (Shape 違いで JIT の方が遅いのはたぶんバグ )