GetItem optimization + delete_item fix#2600
Merged
hoffstadt merged 4 commits intohoffstadt:masterfrom Jan 26, 2026
Merged
Conversation
…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.
… the cache is nearly useless.
hoffstadt
approved these changes
Jan 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
name: Pull Request
about: Create a pull request to help us improve
title: GetItem optimization
assignees: ''
Closes #2374
Description:
Currently,
mvAppItemlookup 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_searchbecomes useless and is therefore deprecated, as well as theis_item_search_delayedfunction (which didn't work anyway).Also,
move_itemnow performs the same checks on item compatibility asadd_XXXfunctions do (it just callsAddItemWithRuntimeChecks). 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,
mvAppItemcannot outlive adelete_itemcall 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_itemanymore. While this mechanism is still supported by DPG, the code indemo.pytries 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.