Type: Add TypeManager->TypeList() and use for ListVal()

It turns out that for every ListVal we construct, we also allocate
and construct a new TypeList instance, even though they are all the
same. Pre-create and cache the type instances in a new TypeManager.

The following script runs ~10% faster for me after this change.

    global tbl: table[string] of string;
    global i = 0;
    while ( ++i < 10000000 )
        tbl["a"] = "a";
This commit is contained in:
Arne Welzel 2023-03-30 19:36:26 +02:00
parent 04a2ee7220
commit 24c606b4df
4 changed files with 36 additions and 4 deletions

View file

@ -1981,6 +1981,22 @@ detail::TraversalCode VectorType::Traverse(detail::TraversalCallback* cb) const
HANDLE_TC_TYPE_POST(tc);
}
TypeManager::TypeManager()
{
for ( auto i = 0u; i < base_list_types.size(); ++i )
{
TypeTag tag = static_cast<TypeTag>(i);
TypePtr pure_type = tag == TYPE_ANY ? nullptr : base_type(tag);
base_list_types[tag] = make_intrusive<zeek::TypeList>(pure_type);
}
}
const TypeListPtr& TypeManager::TypeList(TypeTag t) const
{
assert(t >= 0 && t < NUM_TYPES);
return base_list_types[t];
}
// Returns true if t1 is initialization-compatible with t2 (i.e., if an
// initializer with type t1 can be used to initialize a value with type t2),
// false otherwise. Assumes that t1's tag is different from t2's. Note