Commit 527289ad authored by Chris Toshok's avatar Chris Toshok

use a ContiguousMap instead of a stringmap -> HiddenClass

when looking up a child hidden class we look up the attr in the child_index map,
then get the HiddenClass* from the children vector (at that index.)

this speeds up GC substantially by letting us visit the range from the vector as
opposed to iterating through the stringmap.
parent 3428efc2
...@@ -191,6 +191,9 @@ bool GCVisitor::isValid(void* p) { ...@@ -191,6 +191,9 @@ bool GCVisitor::isValid(void* p) {
} }
void GCVisitor::visit(void* p) { void GCVisitor::visit(void* p) {
if (!p)
return;
if (isNonheapRoot(p)) { if (isNonheapRoot(p)) {
return; return;
} else { } else {
......
...@@ -474,7 +474,7 @@ HiddenClass* HiddenClass::getOrMakeChild(const std::string& attr) { ...@@ -474,7 +474,7 @@ HiddenClass* HiddenClass::getOrMakeChild(const std::string& attr) {
auto it = children.find(attr); auto it = children.find(attr);
if (it != children.end()) if (it != children.end())
return it->second; return children.getMapped(it->second);
static StatCounter num_hclses("num_hidden_classes"); static StatCounter num_hclses("num_hidden_classes");
num_hclses.log(); num_hclses.log();
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "structmember.h" #include "structmember.h"
#include "codegen/irgen/future.h" #include "codegen/irgen/future.h"
#include "core/contiguous_map.h"
#include "core/threading.h" #include "core/threading.h"
#include "core/types.h" #include "core/types.h"
#include "gc/gc_alloc.h" #include "gc/gc_alloc.h"
...@@ -286,7 +287,7 @@ private: ...@@ -286,7 +287,7 @@ private:
// Only makes sense for NORMAL hidden classes. Clients should access through getAttrOffsets(): // Only makes sense for NORMAL hidden classes. Clients should access through getAttrOffsets():
llvm::StringMap<int> attr_offsets; llvm::StringMap<int> attr_offsets;
llvm::StringMap<HiddenClass*> children; ContiguousMap<llvm::StringRef, HiddenClass*, llvm::StringMap<int>> children;
public: public:
static HiddenClass* makeRoot() { static HiddenClass* makeRoot() {
...@@ -308,11 +309,8 @@ public: ...@@ -308,11 +309,8 @@ public:
void gc_visit(GCVisitor* visitor) { void gc_visit(GCVisitor* visitor) {
// Visit children even for the dict-backed case, since children will just be empty // Visit children even for the dict-backed case, since children will just be empty
for (const auto& p : children) { visitor->visitRange((void* const*)&children.vector()[0], (void* const*)&children.vector()[children.size()]);
visitor->visit(p.second);
} }
}
// Only makes sense for NORMAL hidden classes: // Only makes sense for NORMAL hidden classes:
const llvm::StringMap<int>& getAttrOffsets() { const llvm::StringMap<int>& getAttrOffsets() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment