diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-07-20 14:27:14 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-07-20 14:27:14 +0300 |
commit | 7f8d05131a7738327ae125d065df44be492ff1f2 (patch) | |
tree | 2e3e13596dee6bc747ed285374ea83d977b7c745 /source/blender/blenloader | |
parent | 8d69c6c4e7c5417f88603d5ccb2c4bb0e156aa1e (diff) |
IDManagement: Speedup ID unique name assignment by tracking used names/basenames/suffixes
An implementation of T73412, roughly as outlined there:
Track the names that are in use, as well as base names (before
numeric suffix) plus a bit map for each base name, indicating which
numeric suffixes are already used. This is done per-Main/Library,
per-object-type.
Timings (Windows, VS2022 Release build, AMD Ryzen 5950X):
- Scene with 10k cubes, Shift+D to duplicate them all: 8.7s -> 1.9s.
Name map memory usage for resulting 20k objects: 4.3MB.
- Importing a 2.5GB .obj file of exported Blender 3.0 splash scene
(24k objects), using the new C++ importer: 34.2s-> 22.0s. Name map
memory usage for resulting scene: 8.6MB.
- Importing Disney Moana USD scene (almost half a million objects):
56min -> 10min. Name map usage: ~100MB. Blender crashes later on
when trying to render it, in the same place in both cases, but
that's for another day.
Reviewed By: Bastien Montagne
Differential Revision: https://developer.blender.org/D14162
Diffstat (limited to 'source/blender/blenloader')
5 files changed, 13 insertions, 11 deletions
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c index 67b6ad25d8b..ffa224ea9e0 100644 --- a/source/blender/blenloader/intern/versioning_250.c +++ b/source/blender/blenloader/intern/versioning_250.c @@ -425,14 +425,14 @@ static void do_versions_windowmanager_2_50(bScreen *screen) } } -static void versions_gpencil_add_main(ListBase *lb, ID *id, const char *name) +static void versions_gpencil_add_main(Main *bmain, ListBase *lb, ID *id, const char *name) { BLI_addtail(lb, id); id->us = 1; id->flag = LIB_FAKEUSER; *((short *)id->name) = ID_GD; - BKE_id_new_name_validate(lb, id, name, false); + BKE_id_new_name_validate(bmain, lb, id, name, false); /* alphabetic insertion: is in BKE_id_new_name_validate */ if ((id->tag & LIB_TAG_TEMP_MAIN) == 0) { @@ -455,21 +455,21 @@ static void do_versions_gpencil_2_50(Main *main, bScreen *screen) if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; if (v3d->gpd) { - versions_gpencil_add_main(&main->gpencils, (ID *)v3d->gpd, "GPencil View3D"); + versions_gpencil_add_main(main, &main->gpencils, (ID *)v3d->gpd, "GPencil View3D"); v3d->gpd = NULL; } } else if (sl->spacetype == SPACE_NODE) { SpaceNode *snode = (SpaceNode *)sl; if (snode->gpd) { - versions_gpencil_add_main(&main->gpencils, (ID *)snode->gpd, "GPencil Node"); + versions_gpencil_add_main(main, &main->gpencils, (ID *)snode->gpd, "GPencil Node"); snode->gpd = NULL; } } else if (sl->spacetype == SPACE_SEQ) { SpaceSeq *sseq = (SpaceSeq *)sl; if (sseq->gpd) { - versions_gpencil_add_main(&main->gpencils, (ID *)sseq->gpd, "GPencil Node"); + versions_gpencil_add_main(main, &main->gpencils, (ID *)sseq->gpd, "GPencil Node"); sseq->gpd = NULL; } } @@ -477,7 +477,7 @@ static void do_versions_gpencil_2_50(Main *main, bScreen *screen) SpaceImage *sima = (SpaceImage *)sl; #if 0 /* see comment on r28002 */ if (sima->gpd) { - versions_gpencil_add_main(&main->gpencil, (ID *)sima->gpd, "GPencil Image"); + versions_gpencil_add_main(main, &main->gpencil, (ID *)sima->gpd, "GPencil Image"); sima->gpd = NULL; } #else diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index 82e24801b66..cd2132ddae9 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -3549,7 +3549,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) if (!MAIN_VERSION_ATLEAST(bmain, 280, 43)) { ListBase *lb = which_libbase(bmain, ID_BR); - BKE_main_id_repair_duplicate_names_listbase(lb); + BKE_main_id_repair_duplicate_names_listbase(bmain, lb); } if (!MAIN_VERSION_ATLEAST(bmain, 280, 44)) { diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c index de652b40590..9ab744337a8 100644 --- a/source/blender/blenloader/intern/versioning_290.c +++ b/source/blender/blenloader/intern/versioning_290.c @@ -849,7 +849,7 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain) short id_codes[] = {ID_BR, ID_PAL}; for (int i = 0; i < ARRAY_SIZE(id_codes); i++) { ListBase *lb = which_libbase(bmain, id_codes[i]); - BKE_main_id_repair_duplicate_names_listbase(lb); + BKE_main_id_repair_duplicate_names_listbase(bmain, lb); } } diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 14204479849..bbbeba4d687 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -2017,7 +2017,7 @@ void blo_do_versions_300(FileData *fd, Library *UNUSED(lib), Main *bmain) /* Font names were copied directly into ID names, see: T90417. */ if (!MAIN_VERSION_ATLEAST(bmain, 300, 16)) { ListBase *lb = which_libbase(bmain, ID_VF); - BKE_main_id_repair_duplicate_names_listbase(lb); + BKE_main_id_repair_duplicate_names_listbase(bmain, lb); } if (!MAIN_VERSION_ATLEAST(bmain, 300, 17)) { diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c index 6ce53e4a648..dfd98cb94f3 100644 --- a/source/blender/blenloader/intern/versioning_defaults.c +++ b/source/blender/blenloader/intern/versioning_defaults.c @@ -479,8 +479,10 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template) /* Default only has one window. */ if (layout->screen) { bScreen *screen = layout->screen; - BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2); - BLI_libblock_ensure_unique_name(bmain, screen->id.name); + if (!STREQ(screen->id.name + 2, workspace->id.name + 2)) { + BLI_strncpy(screen->id.name + 2, workspace->id.name + 2, sizeof(screen->id.name) - 2); + BLI_libblock_ensure_unique_name(bmain, screen->id.name); + } } /* For some reason we have unused screens, needed until re-saving. |