Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up first time type lookups #1148

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions shared/sdk/RETypeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,33 @@ reframework::InvokeRet invoke_object_func(::REManagedObject* obj, std::string_vi
}

sdk::RETypeDefinition* RETypeDB::find_type(std::string_view name) const {
static bool map_populated = false;

{
std::shared_lock _{ g_tdb_type_mtx };

if (auto it = g_tdb_type_map.find(name.data()); it != g_tdb_type_map.end()) {
return it->second;
}

if (map_populated) {
return nullptr;
}
}

for (uint32_t i = 0; i < this->numTypes; ++i) {
auto t = get_type(i);
{
std::unique_lock _{ g_tdb_type_mtx };

map_populated = true;

if (t->get_full_name() == name) {
std::unique_lock _{ g_tdb_type_mtx };
for (uint32_t i = 0; i < this->numTypes; ++i) {
auto t = get_type(i);

g_tdb_type_map[name.data()] = t;
return g_tdb_type_map[name.data()];
g_tdb_type_map[t->get_full_name()] = t;
}
}

std::unique_lock _{ g_tdb_type_mtx };
return g_tdb_type_map[name.data()];
return this->find_type(name);
}

sdk::RETypeDefinition* RETypeDB::find_type_by_fqn(uint32_t fqn) const {
Expand Down Expand Up @@ -1152,4 +1158,4 @@ std::vector<const char*> REMethodDefinition::get_param_names() const {
return out;
#endif
}
} // namespace sdk
} // namespace sdk
Loading