From 46607bc09d5cd9fa3570e5ad4b01ea4ea7adaffc Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 19 Dec 2019 21:58:59 +0100 Subject: ID Management: Improve speed of code used when creating/renaming and ID. This commit affects `id_sort_by_name()` and `check_for_dupid()` helper: * Add a new parameter, `ID *id_sorting_hint`, to `id_sort_by_name()`, and when non-NULL, check if we can insert `id` immediately before or after it. This can dramatically reduce time spent in that function. * Use loop over whole list in `check_for_dupid()` to also define the likely ID pointer that will be neighbor with our new one. This gives another decent speedup to all massive addition cases: | Number and type of names of IDs | old code | new code | speed improvement | | -------------------------------- | -------- | -------- | ----------------- | | 40K, mixed (14k rand, 26k const) | 39s | 33s | 18% | | 40K, fully random | 51s | 42s | 21% | | 40K, fully constant | 40s | 34s | 18% | Combined with the previous commits, this makes massive addition of IDs more than twice as fast as previously. --- source/blender/blenkernel/BKE_library.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source/blender/blenkernel/BKE_library.h') diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h index 71799bf74f6..c41cd50eba5 100644 --- a/source/blender/blenkernel/BKE_library.h +++ b/source/blender/blenkernel/BKE_library.h @@ -199,7 +199,7 @@ bool BKE_id_copy_is_allowed(const struct ID *id); bool BKE_id_copy(struct Main *bmain, const struct ID *id, struct ID **newid); bool BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag); void BKE_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b); -void id_sort_by_name(struct ListBase *lb, struct ID *id); +void id_sort_by_name(struct ListBase *lb, struct ID *id, struct ID *id_sorting_hint); void BKE_id_expand_local(struct Main *bmain, struct ID *id); void BKE_id_copy_ensure_local(struct Main *bmain, const struct ID *old_id, struct ID *new_id); -- cgit v1.2.3