Skip to content

GetItem optimization + delete_item fix#2600

Merged
hoffstadt merged 4 commits intohoffstadt:masterfrom
v-ein:feature/2374-hashmap-based-getitem
Jan 26, 2026
Merged

GetItem optimization + delete_item fix#2600
hoffstadt merged 4 commits intohoffstadt:masterfrom
v-ein:feature/2374-hashmap-based-getitem

Conversation

@v-ein
Copy link
Collaborator

@v-ein v-ein commented Jan 21, 2026


name: Pull Request
about: Create a pull request to help us improve
title: GetItem optimization
assignees: ''


Closes #2374

Description:
Currently, mvAppItem lookup by its UUID (i.e. given the UUID, find its mvAppItem) typically uses a straightforward tree search, slightly optimized by adding a linear cache of 25 items + 25 containers. This PR changes the lookup to use a hashmap (std::unordered_map) and removes all tree lookups where possible. As a result, access time does not depend on whether the item is in the cache anymore (the cache is not used either). In my benchmarks, access times in the new version were comparable (nearly identical) with access to a cached item in the old version. On a cache miss, the old version may be significantly slower (something like 800x slower for a widget tree of 2000 items).

The delay_search becomes useless and is therefore deprecated, as well as the is_item_search_delayed function (which didn't work anyway).

Also, move_item now performs the same checks on item compatibility as add_XXX functions do (it just calls AddItemWithRuntimeChecks). Earlier, it was possible to move item to an incompatible parent. There's still a chance to move item to a slot it should not belong to, but this should be fixed by a separate PR.

Another change this PR makes affects the callback registry. For most callbacks, there's an "owner" mvAppItem that DPG currently keeps alive all the while until the callback ends. Starting with this PR, the owner is only kept alive for a short moment right before the callback starts execution - to obtain the PyObject that points to the callback itself. Once the callback PyObject is obtained from the owner, the owner is released and can be deleted at any moment, e.g. from another thread. This simplifies item access that othewise would require some complex rules. That is, with this PR, mvAppItem cannot outlive a delete_item call anymore. This is exactly the change I mentioned in #2580 (see the my last sentence).

Yet another small change is that the demo doesn't use capture_next_item anymore. While this mechanism is still supported by DPG, the code in demo.py tries to use it in a situation where there's absolutely no need for such a call. This makes for a poor usage example and we shouldn't encourage such usage, so I preferred to get rid of that.

Concerning Areas:
None.

v-ein added 4 commits January 21, 2026 22:17
…lookups. This speeds up most API functions. hoffstadt#2374

In callback registry, the owner mvAppItem is released right after obtaining the callback from it in the handlers thread. Makes mvAppItem lifetime management easier - the item can't outlive the delete_item call anymore. Also, mutex is locked while mvAppItem is released.

Also, deprecated the "delay_search" argument since it's not relevant anymore.
Improved error message when 'before' is not found.
@v-ein v-ein requested a review from hoffstadt January 21, 2026 18:16
@hoffstadt hoffstadt merged commit e56ecdb into hoffstadt:master Jan 26, 2026
4 checks passed
@v-ein v-ein deleted the feature/2374-hashmap-based-getitem branch February 3, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Item edition becomes slow when there are lots of items.

2 participants