perf(cdclient): read ComponentsRegistry, ItemComponent and Objects from the fdb

The world and master servers pass the client's res/cdclient.fdb to
CDClientManager. When it opens, these three tables, all looked up by
their first column, find rows through the fdb's buckets instead of each
process caching the whole table: ComponentsRegistry keeps nothing,
ItemComponent and Objects keep only the entries asked for (their API
returns references). Ids whose rows CDServer.sqlite changes are loaded
from SQLite at startup and win. Without an fdb (or with one whose
columns don't match) the tables load from CDServer.sqlite as before.

ItemComponent and Objects now fill entries from one template for both
sources instead of copies of the same field list.

Tests cover the SQLite changes on top of the fdb, the no-fdb and
unmapped paths, and, when DLU_CLIENT_RES points at a client, every id of
the three tables through the fdb against CDServer.sqlite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 21:56:32 -05:00
parent 17eb26fb1d
commit a4fa7eb30a
12 changed files with 581 additions and 179 deletions

View File

@@ -1,4 +1,6 @@
#include "CDClientManager.h"
#include "CDFdb.h"
#include "Logger.h"
#include "CDActivityRewardsTable.h"
#include "CDAnimationsTable.h"
#include "CDBehaviorParameterTable.h"
@@ -111,11 +113,20 @@ DEFINE_TABLE_STORAGE(CDSkillBehaviorTable);
DEFINE_TABLE_STORAGE(CDTamingBuildPuzzleTable);
DEFINE_TABLE_STORAGE(CDVendorComponentTable);
void CDClientManager::LoadValuesFromDatabase() {
void CDClientManager::LoadValuesFromDatabase(const std::filesystem::path& fdbPath) {
if (!CDClientDatabase::isConnected) {
throw std::runtime_error{ "CDClientDatabase is not connected!" };
}
if (!fdbPath.empty()) {
if (CDFdb::Open(fdbPath)) {
LOG("Reading CDClient rows by id from %s (%s)", fdbPath.string().c_str(),
CDFdb::Get()->IsMapped() ? "mapped, shared between processes" : "could not map it, read into memory");
} else {
LOG("Could not open %s, reading CDClient from CDServer.sqlite only", fdbPath.string().c_str());
}
}
CDActivityRewardsTable::Instance().LoadValuesFromDatabase();
CDActivitiesTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDAnimationsTable::Instance().LoadValuesFromDatabase());
@@ -123,10 +134,11 @@ void CDClientManager::LoadValuesFromDatabase() {
CDBehaviorTemplateTable::Instance().LoadValuesFromDatabase();
CDBrickIDTableTable::Instance().LoadValuesFromDatabase();
CDCollectibleComponentTable::Instance().LoadValuesFromDatabase();
// Always in memory: every entity and every inventory item asks for its components and item data, and looking up an
// ComponentsRegistry, ItemComponent and Objects read rows from the fdb when it is open. Without it, the first two are
// always in memory: every entity and every inventory item asks for its components and item data, and looking up an
// id not seen yet in the unindexed CDClient scans the whole table (a character holding 3000 different items took a
// minute to load)
CDComponentsRegistryTable::Instance().LoadValuesFromDatabase();
if (!CDComponentsRegistryTable::Instance().LoadFromFdb()) CDComponentsRegistryTable::Instance().LoadValuesFromDatabase();
CDCurrencyTableTable::Instance().LoadValuesFromDatabase();
CDDeletionRestrictionsTable::Instance().LoadValuesFromDatabase();
CDDestructibleComponentTable::Instance().LoadValuesFromDatabase();
@@ -134,7 +146,7 @@ void CDClientManager::LoadValuesFromDatabase() {
CDEventGatingTable::Instance().LoadValuesFromDatabase();
CDFeatureGatingTable::Instance().LoadValuesFromDatabase();
CDInventoryComponentTable::Instance().LoadValuesFromDatabase();
CDItemComponentTable::Instance().LoadValuesFromDatabase();
if (!CDItemComponentTable::Instance().LoadFromFdb()) CDItemComponentTable::Instance().LoadValuesFromDatabase();
CDItemSetSkillsTable::Instance().LoadValuesFromDatabase();
CDItemSetsTable::Instance().LoadValuesFromDatabase();
CDLevelProgressionLookupTable::Instance().LoadValuesFromDatabase();
@@ -146,7 +158,7 @@ void CDClientManager::LoadValuesFromDatabase() {
CDMissionsTable::Instance().LoadValuesFromDatabase();
CDMovementAIComponentTable::Instance().LoadValuesFromDatabase();
CDObjectSkillsTable::Instance().LoadValuesFromDatabase();
CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
if (!CDObjectsTable::Instance().LoadFromFdb()) CDCLIENT_DONT_CACHE_TABLE(CDObjectsTable::Instance().LoadValuesFromDatabase());
CDPhysicsComponentTable::Instance().LoadValuesFromDatabase();
CDPackageComponentTable::Instance().LoadValuesFromDatabase();
CDPetComponentTable::Instance().LoadValuesFromDatabase();