Skip to content

Commit e56ecdb

Browse files
v-einhoffstadt
authored andcommitted
perf: Removed item cache - even with the slow-ish std::unordered_map, the cache is nearly useless.
1 parent b64b7c5 commit e56ecdb

5 files changed

Lines changed: 6 additions & 67 deletions

File tree

src/dearpygui_commands.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,10 +3273,7 @@ unstage(PyObject* self, PyObject* args, PyObject* kwargs)
32733273
}
32743274

32753275
if (item_found)
3276-
{
3277-
CleanUpItem(*GContext->itemRegistry, item);
32783276
return GetPyNone();
3279-
}
32803277

32813278
mvThrowPythonError(mvErrorCode::mvItemNotFound, "unstage",
32823279
"Stage not found: " + std::to_string(item), nullptr);

src/mvAppItem.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ mvAppItem::~mvAppItem()
4545
GContext->itemRegistry->aliases.erase(config.alias);
4646
}
4747
GContext->itemRegistry->allItems.erase(uuid);
48-
CleanUpItem(*GContext->itemRegistry, uuid);
4948
}
5049
}
5150

src/mvItemRegistry.cpp

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
mvItemRegistry::mvItemRegistry()
1010
{
11-
// prefill cached containers
12-
for (i32 i = 0; i < CachedContainerCount; i++)
13-
{
14-
cachedContainersID[i] = 0;
15-
cachedContainersPTR[i] = nullptr;
16-
cachedItemsID[i] = 0;
17-
cachedItemsPTR[i] = nullptr;
18-
}
11+
// We seldom need to do a GetItem(0), and an explicit check for uuid == 0 in GetItem
12+
// slows it down. Instead of this, we add a fake entry to the allItems map,
13+
// mapping 0 to nullptr. This entry will never go away because map items are only
14+
// removed in the mvAppItem destructor.
15+
allItems[0] = nullptr;
1916
}
2017

2118
static b8
@@ -47,25 +44,6 @@ TopParent(mvItemRegistry& registry)
4744
return nullptr;
4845
}
4946

50-
static void
51-
CacheItem(mvItemRegistry& registry, mvAppItem* item)
52-
{
53-
if (DearPyGui::GetEntityDesciptionFlags(item->type) & MV_ITEM_DESC_CONTAINER)
54-
{
55-
registry.cachedContainersID[registry.cachedContainerIndex] = item->uuid;
56-
registry.cachedContainersPTR[registry.cachedContainerIndex] = item;
57-
registry.cachedContainerIndex++;
58-
if (registry.cachedContainerIndex == registry.CachedContainerCount)
59-
registry.cachedContainerIndex = 0;
60-
}
61-
62-
registry.cachedItemsID[registry.cachedItemsIndex] = item->uuid;
63-
registry.cachedItemsPTR[registry.cachedItemsIndex] = item;
64-
registry.cachedItemsIndex++;
65-
if (registry.cachedItemsIndex == registry.CachedContainerCount)
66-
registry.cachedItemsIndex = 0;
67-
}
68-
6947
static void
7048
UpdateChildLocations(std::vector<std::shared_ptr<mvAppItem>>* children, i32 slots)
7149
{
@@ -310,10 +288,6 @@ RemoveItemFromTree(mvItemRegistry& registry, mvAppItem* item)
310288
b8
311289
DeleteItem(mvItemRegistry& registry, mvUUID uuid, b8 childrenOnly, i32 slot)
312290
{
313-
314-
// TODO: we probably don't need this anymore (well, only if we remove the cache)
315-
CleanUpItem(registry, uuid);
316-
317291
mvAppItem* item = GetItem(registry, uuid);
318292
if (!item)
319293
{
@@ -745,25 +719,6 @@ ClearItemRegistry(mvItemRegistry& registry)
745719
registry.viewportDrawlistRoots.clear();
746720
}
747721

748-
void
749-
CleanUpItem(mvItemRegistry& registry, mvUUID uuid)
750-
{
751-
for (i32 i = 0; i < registry.CachedContainerCount; i++)
752-
{
753-
if (registry.cachedContainersID[i] == uuid)
754-
{
755-
registry.cachedContainersID[i] = 0;
756-
registry.cachedContainersPTR[i] = nullptr;
757-
}
758-
759-
if (registry.cachedItemsID[i] == uuid)
760-
{
761-
registry.cachedItemsID[i] = 0;
762-
registry.cachedItemsPTR[i] = nullptr;
763-
}
764-
}
765-
}
766-
767722
b8
768723
AddItemWithRuntimeChecks(mvItemRegistry& registry, std::shared_ptr<mvAppItem> item, mvUUID parent, mvUUID before)
769724
{
@@ -803,8 +758,6 @@ AddItemWithRuntimeChecks(mvItemRegistry& registry, std::shared_ptr<mvAppItem> it
803758

804759
registry.lastItemAdded = item->uuid;
805760

806-
CacheItem(registry, item.get());
807-
808761
//---------------------------------------------------------------------------
809762
// STEP 1: check if an item with this name exists (NO LONGER NEEDED)
810763
//---------------------------------------------------------------------------

src/mvItemRegistry.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void RenderItemRegistry(mvItemRegistry& registry);
2424

2525
// cleanup
2626
void ClearItemRegistry(mvItemRegistry& registry);
27-
void CleanUpItem (mvItemRegistry& registry, mvUUID uuid);
2827
b8 DeleteItem (mvItemRegistry& registry, mvUUID uuid, b8 childrenOnly = false, i32 slot = -1);
2928

3029
// aliases
@@ -64,18 +63,10 @@ b8 ReorderChildren (mvItemRegistry& registry, mvUUID paren
6463
struct mvItemRegistry
6564
{
6665

67-
static constexpr i32 CachedContainerCount = 25;
68-
69-
// caching
66+
// "last item" state
7067
mvUUID lastItemAdded = 0;
7168
mvUUID lastContainerAdded = 0;
7269
mvUUID lastRootAdded = 0;
73-
i32 cachedContainerIndex = 0;
74-
i32 cachedItemsIndex = 0;
75-
mvUUID cachedItemsID[CachedContainerCount];
76-
mvAppItem* cachedItemsPTR[CachedContainerCount];
77-
mvUUID cachedContainersID[CachedContainerCount];
78-
mvAppItem* cachedContainersPTR[CachedContainerCount];
7970

8071
// misc
8172
std::stack<mvAppItem*> containers; // parent stack, top of stack becomes widget's parent

src/mvNodes.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ void mvNodeEditor::onChildRemoved(std::shared_ptr<mvAppItem> item)
107107
if (i1 == attr_id || i2 == attr_id)
108108
{
109109
DeleteItem(*GContext->itemRegistry, child->uuid);
110-
CleanUpItem(*GContext->itemRegistry, child->uuid);
111110
}
112111
}
113112
}

0 commit comments

Comments
 (0)