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 (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フレームワーク Doma
Toshihiro Nakamura
 
アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—アジャイル事例紹介 —夜のおしごと編—
アジャイル事例紹介 —夜のおしごと編—
Fumihiko Kinoshita
 
技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac技術トレンディセミナー フレームワークとしてのTrac
技術トレンディセミナー フレームワークとしてのTrac
terada
 
Ohp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 MojiretsuOhp Seijoen H20 06 Mojiretsu
Ohp Seijoen H20 06 Mojiretsu
sesejun
 
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 Mobile
Hiroshi 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
 

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 (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

+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
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
Safe Software
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
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...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
+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...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
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...
 
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, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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?
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
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
 

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