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

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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
 
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
 
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
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 

Recently uploaded (20)

DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
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
 
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...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

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 の方が遅いのはたぶんバグ )