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 Optimize JavaScript Performance with Shape Polymorphism Caching

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 Optimize JavaScript Performance with Shape Polymorphism Caching (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

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

Optimize JavaScript Performance with Shape Polymorphism Caching

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