Use hash for Collection.gobject lookup, speedup object linking #104553

Closed
Campbell Barton wants to merge 5 commits from ideasman42:pr-collection-object-hash into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

5 Commits

Author SHA1 Message Date
Campbell Barton 028b6e06a2 Experimental removal of object argument
buildbot/vexp-code-patch-coordinator Build done. Details
2023-02-21 21:43:45 +11:00
Campbell Barton bc06586a34 Fix crash found when running tests (import_ply_cube failed for e.g.) 2023-02-19 15:46:28 +11:00
Campbell Barton 960e11887d Updates based on review (will be squished)
- Add `collection_object_remove_no_gobject_hash` useful for clearing all
  objects in a collection as there is no need for a lookup in this case.
- Use BLI_ghash_ensure_p to avoid multiple lookups.
- Functions now ensure the hash:
  BKE_collection_has_object, BKE_collection_object_replace.
- Improve code-comments.
2023-02-19 15:46:28 +11:00
Campbell Barton 3b29b99b90 Address review (this commit will be squished)
- Rename collection_gobject_hash_replace_object_pair, remove redundant argument.
- Move BLI_ASSERT_COLLECION_GOBJECT_HASH_IS_VALID into collection_gobject_hash_ensure
- Correct poorly worded sentence.
- Remove overly paranoid assert.
2023-02-19 15:46:28 +11:00
Campbell Barton a127d2ecaa Use hash for Collection.gobject lookup, speedup object linking
Add a hash for faster look-ups on collection->gobject,
This avoids a full list lookup for every object added via Python's
CollectionObject.link as well as linking via BKE_collection_object_add_*
functions.

While the speedup is non-linear, linking & unlinking 100k objects from
Python is about 50x faster. Although unlinking all objects in order
(a best-case for linked lists) is ~18% slower.
2023-02-19 15:46:28 +11:00