summaryrefslogtreecommitdiff
path: root/rjit_c.rb
diff options
context:
space:
mode:
authorAaron Patterson <tenderlove@ruby-lang.org>2023-02-07 17:46:42 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2023-10-24 10:52:06 -0700
commit84e4453436c3549b4fda6014cdd5fcc9e0b80755 (patch)
treef0fdc61a51a8f1cfa5eb9b534103d1534a29b5ae /rjit_c.rb
parent5c4978c11c4ea9569d5d99a86936fbef0ab7fa52 (diff)
Use a functional red-black tree for indexing the shapes
This is an experimental commit that uses a functional red-black tree to create an index of the ancestor shapes. It uses an Okasaki style functional red black tree: https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf This tree is advantageous because: * It offers O(n log n) insertions and O(n log n) lookups. * It shares memory with previous "versions" of the tree When we insert a node in the tree, only the parts of the tree that need to be rebalanced are newly allocated. Parts of the tree that don't need to be rebalanced are not reallocated, so "new trees" are able to share memory with old trees. This is in contrast to a sorted set where we would have to duplicate the set, and also resort the set on each insertion. I've added a new stat to RubyVM.stat so we can understand how the red black tree increases.
Diffstat (limited to 'rjit_c.rb')
-rw-r--r--rjit_c.rb5
1 files changed, 5 insertions, 0 deletions
diff --git a/rjit_c.rb b/rjit_c.rb
index 72e8221cbc..949040e10e 100644
--- a/rjit_c.rb
+++ b/rjit_c.rb
@@ -1483,6 +1483,7 @@ module RubyVM::RJIT # :nodoc: all
type: [CType::Immediate.parse("uint8_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), type)")],
size_pool_index: [CType::Immediate.parse("uint8_t"), Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), size_pool_index)")],
parent_id: [self.shape_id_t, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), parent_id)")],
+ ancestor_index: [CType::Pointer.new { self.redblack_node_t }, Primitive.cexpr!("OFFSETOF((*((struct rb_shape *)NULL)), ancestor_index)")],
)
end
@@ -1641,6 +1642,10 @@ module RubyVM::RJIT # :nodoc: all
CType::Bool.new
end
+ def C.redblack_node_t
+ CType::Stub.new(:redblack_node_t)
+ end
+
def C.ccan_list_node
CType::Stub.new(:ccan_list_node)
end