SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Downloaden Sie, um offline zu lesen
@
Kaigi The Future Shape of Ruby Objects 202:1
name: ‘Chris’
age: 36
company: ‘Shopify’
home: ‘Cheshire’
struct RObject {
VALUE klass;
int numiv;
VALUE[] ivptr;
};
struct RClass {
struct st_table *iv_index_tbl; // Hash of Symbol -> index
};
VALUE vm_getivar(VALUE obj, IVC inline_cache) {
if (inline_cache && inline_cache->class_serial == obj->klass->class_serial) {
int index = inline_cache->index;
if (obj->type == T_OBJECT) && index < obj->numiv) {
return obj->ivptr[index];
} else {
// slow path
}
} else {
// slow path
}
}
VALUE vm_setivar(VALUE obj, VALUE val, IVC inline_cache) {
if (inline_cache && inline_cache->class_serial == obj->klass->class_serial) {
int index = inline_cache->index;
if (obj->type == T_OBJECT) && index < obj->numiv) {
obj->ivptr[index] = val;
} else {
// slow path
} } else {
// slow path
}
}
def vm_getivar(cache, obj)
if cache.serial == obj.klass.serial && cache.index < obj.numiv
obj.ivptr[cache.index]
else
# slow path
end
end
def vm_setivar(cache, obj, val)
if cache.serial == obj.klass.serial && cache.index < obj.numiv
obj.ivptr[cache.index] = val
else
# slow path
end
end
class TwoVariablesObject {
Object var0;
Object var1;
}
def vm_getivar(cache, obj)
if cache.id == obj.getMetaClass().getRealClass().id
obj[cache.index]
else
# slow path
end
end
name: 0
home: 1
company: 2
age: 3
klass
shape
‘Chris’
‘Cheshire’
‘Shopify’
36
index = obj.shape[:name]
obj[index]
index = obj.shape[:name]
obj[index] = value
name: 0
home: 1
company: 2
age: 3
klass
shape
‘Chris’
‘Cheshire’
‘Shopify’
36
181 name: 0
home: 1
company: 2
age: 3
height: 4
+ height
new_shape = obj.shape.transitions[:add_height]
index = new_shape[:name]
obj.shape = new_shape
obj.resize
obj[index] = value
slow_path unless obj.shape == 0x12345678
obj[4]
def getter
@ivar
End
0x1242ec600: cmp dword ptr [rax*8 + 0xc], expected_shape
0x1242ec60b: jne slow_path
0x1242ec611: mov r10d, dword ptr [rax*8 + index]
def setter(value)
@ivar = value
end
0x11fd28a00: cmp dword ptr [rsi*8 + 0xc], expected_shape
0x11fd28a0b: jne slow_path
0x11fd28a1f: mov qword ptr [rsi*8 + 0x20], r10
def add
@a + @b
end
0x12258d380: cmp dword ptr [rax*8 + 0xc], expected_shape
0x12258d38b: jne slow_path
0x12258d391: mov esi, dword ptr [rax*8 + index_a]
0x12258d398: mov eax, dword ptr [rax*8 + index_b]
0x12258d39f: mov r10d, eax
0x12258d3a2: add r10d, esi
0x12258d3a5: jo overflow
name: 0
home: 1
company: 2
age: 3
klass
shape
‘Chris’
‘Cheshire’
‘Shopify’
36
181 name: 0
home: 1
company: 2
age: 3
(frozen)
freeze
0x11fd28a00: cmp dword ptr [rsi*8 + 0xc], expected_shape
0x11fd28a0b: jne slow_path
0x11fd28a11: mov eax, dword ptr [rdx + index]
@chrisgseaton

Weitere ähnliche Inhalte

Was ist angesagt?

Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
S Akai
 

Was ist angesagt? (20)

The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202The Ring programming language version 1.8 book - Part 43 of 202
The Ring programming language version 1.8 book - Part 43 of 202
 
The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181The Ring programming language version 1.5.2 book - Part 30 of 181
The Ring programming language version 1.5.2 book - Part 30 of 181
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
Deriving Scalaz
Deriving ScalazDeriving Scalaz
Deriving Scalaz
 
Real World Generics In Swift
Real World Generics In SwiftReal World Generics In Swift
Real World Generics In Swift
 
Scalaz
ScalazScalaz
Scalaz
 
From android/ java to swift (2)
From android/ java to swift (2)From android/ java to swift (2)
From android/ java to swift (2)
 
Adopting Swift Generics
Adopting Swift GenericsAdopting Swift Generics
Adopting Swift Generics
 
2 dimension array in programms
2 dimension array in programms2 dimension array in programms
2 dimension array in programms
 
The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210The Ring programming language version 1.9 book - Part 46 of 210
The Ring programming language version 1.9 book - Part 46 of 210
 
Spark Schema For Free with David Szakallas
 Spark Schema For Free with David Szakallas Spark Schema For Free with David Szakallas
Spark Schema For Free with David Szakallas
 
The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84The Ring programming language version 1.2 book - Part 22 of 84
The Ring programming language version 1.2 book - Part 22 of 84
 
The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185The Ring programming language version 1.5.4 book - Part 38 of 185
The Ring programming language version 1.5.4 book - Part 38 of 185
 
Objective-C Survives
Objective-C SurvivesObjective-C Survives
Objective-C Survives
 
Learn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik CubeLearn JavaScript by modeling Rubik Cube
Learn JavaScript by modeling Rubik Cube
 
The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185The Ring programming language version 1.5.4 book - Part 31 of 185
The Ring programming language version 1.5.4 book - Part 31 of 185
 
Constructors
ConstructorsConstructors
Constructors
 
The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189The Ring programming language version 1.6 book - Part 35 of 189
The Ring programming language version 1.6 book - Part 35 of 189
 
RubyistのためのObjective-C入門
RubyistのためのObjective-C入門RubyistのためのObjective-C入門
RubyistのためのObjective-C入門
 
C++ nothrow movable types
C++ nothrow movable typesC++ nothrow movable types
C++ nothrow movable types
 

Ähnlich wie The Future Shape of Ruby Objects

Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Alex Sharp
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
RORLAB
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
Databricks
 

Ähnlich wie The Future Shape of Ruby Objects (20)

The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
PyData Paris 2015 - Track 1.2 Gilles Louppe
PyData Paris 2015 - Track 1.2 Gilles LouppePyData Paris 2015 - Track 1.2 Gilles Louppe
PyData Paris 2015 - Track 1.2 Gilles Louppe
 
The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31The Ring programming language version 1.4.1 book - Part 13 of 31
The Ring programming language version 1.4.1 book - Part 13 of 31
 
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van HovellAn Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
An Introduction to Higher Order Functions in Spark SQL with Herman van Hovell
 
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
5_MariaDB_What's New in MariaDB Server 10.2 and Big Data Analytics with Maria...
 
c#(loops,arrays)
c#(loops,arrays)c#(loops,arrays)
c#(loops,arrays)
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 
Working With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and ModelingWorking With a Real-World Dataset in Neo4j: Import and Modeling
Working With a Real-World Dataset in Neo4j: Import and Modeling
 
ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2ActiveRecord Query Interface (2), Season 2
ActiveRecord Query Interface (2), Season 2
 
The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210The Ring programming language version 1.9 book - Part 53 of 210
The Ring programming language version 1.9 book - Part 53 of 210
 
Importing Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflowImporting Data into Neo4j quickly and easily - StackOverflow
Importing Data into Neo4j quickly and easily - StackOverflow
 
Score (smart contract for icon)
Score (smart contract for icon) Score (smart contract for icon)
Score (smart contract for icon)
 
The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31The Ring programming language version 1.5 book - Part 8 of 31
The Ring programming language version 1.5 book - Part 8 of 31
 
Apache Spark for Library Developers with William Benton and Erik Erlandson
 Apache Spark for Library Developers with William Benton and Erik Erlandson Apache Spark for Library Developers with William Benton and Erik Erlandson
Apache Spark for Library Developers with William Benton and Erik Erlandson
 
Spark schema for free with David Szakallas
Spark schema for free with David SzakallasSpark schema for free with David Szakallas
Spark schema for free with David Szakallas
 
The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185The Ring programming language version 1.5.4 book - Part 30 of 185
The Ring programming language version 1.5.4 book - Part 30 of 185
 
Node.js extensions in C++
Node.js extensions in C++Node.js extensions in C++
Node.js extensions in C++
 
The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84The Ring programming language version 1.2 book - Part 19 of 84
The Ring programming language version 1.2 book - Part 19 of 84
 
The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180The Ring programming language version 1.5.1 book - Part 43 of 180
The Ring programming language version 1.5.1 book - Part 43 of 180
 

Kürzlich hochgeladen

Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 

The Future Shape of Ruby Objects

  • 1. @ Kaigi The Future Shape of Ruby Objects 202:1
  • 2. name: ‘Chris’ age: 36 company: ‘Shopify’ home: ‘Cheshire’
  • 3. struct RObject { VALUE klass; int numiv; VALUE[] ivptr; }; struct RClass { struct st_table *iv_index_tbl; // Hash of Symbol -> index };
  • 4. VALUE vm_getivar(VALUE obj, IVC inline_cache) { if (inline_cache && inline_cache->class_serial == obj->klass->class_serial) { int index = inline_cache->index; if (obj->type == T_OBJECT) && index < obj->numiv) { return obj->ivptr[index]; } else { // slow path } } else { // slow path } } VALUE vm_setivar(VALUE obj, VALUE val, IVC inline_cache) { if (inline_cache && inline_cache->class_serial == obj->klass->class_serial) { int index = inline_cache->index; if (obj->type == T_OBJECT) && index < obj->numiv) { obj->ivptr[index] = val; } else { // slow path } } else { // slow path } }
  • 5. def vm_getivar(cache, obj) if cache.serial == obj.klass.serial && cache.index < obj.numiv obj.ivptr[cache.index] else # slow path end end def vm_setivar(cache, obj, val) if cache.serial == obj.klass.serial && cache.index < obj.numiv obj.ivptr[cache.index] = val else # slow path end end
  • 6. class TwoVariablesObject { Object var0; Object var1; } def vm_getivar(cache, obj) if cache.id == obj.getMetaClass().getRealClass().id obj[cache.index] else # slow path end end
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. name: 0 home: 1 company: 2 age: 3 klass shape ‘Chris’ ‘Cheshire’ ‘Shopify’ 36
  • 15. name: 0 home: 1 company: 2 age: 3 klass shape ‘Chris’ ‘Cheshire’ ‘Shopify’ 36 181 name: 0 home: 1 company: 2 age: 3 height: 4 + height
  • 16. new_shape = obj.shape.transitions[:add_height] index = new_shape[:name] obj.shape = new_shape obj.resize obj[index] = value
  • 17. slow_path unless obj.shape == 0x12345678 obj[4]
  • 18.
  • 19. def getter @ivar End 0x1242ec600: cmp dword ptr [rax*8 + 0xc], expected_shape 0x1242ec60b: jne slow_path 0x1242ec611: mov r10d, dword ptr [rax*8 + index]
  • 20. def setter(value) @ivar = value end 0x11fd28a00: cmp dword ptr [rsi*8 + 0xc], expected_shape 0x11fd28a0b: jne slow_path 0x11fd28a1f: mov qword ptr [rsi*8 + 0x20], r10
  • 21.
  • 22. def add @a + @b end 0x12258d380: cmp dword ptr [rax*8 + 0xc], expected_shape 0x12258d38b: jne slow_path 0x12258d391: mov esi, dword ptr [rax*8 + index_a] 0x12258d398: mov eax, dword ptr [rax*8 + index_b] 0x12258d39f: mov r10d, eax 0x12258d3a2: add r10d, esi 0x12258d3a5: jo overflow
  • 23. name: 0 home: 1 company: 2 age: 3 klass shape ‘Chris’ ‘Cheshire’ ‘Shopify’ 36 181 name: 0 home: 1 company: 2 age: 3 (frozen) freeze
  • 24. 0x11fd28a00: cmp dword ptr [rsi*8 + 0xc], expected_shape 0x11fd28a0b: jne slow_path 0x11fd28a11: mov eax, dword ptr [rdx + index]