2023-08-15 16:20:26 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
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
2022-07-20 13:27:14 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
|
|
|
*
|
|
|
|
* API to ensure name uniqueness.
|
|
|
|
*
|
|
|
|
* Main database contains the UniqueName_Map which is a cache that tracks names, base
|
|
|
|
* names and their suffixes currently in use. So that whenever a new name has to be
|
|
|
|
* assigned or validated, it can quickly ensure uniqueness and adjust the name in case
|
|
|
|
* of collisions.
|
|
|
|
*
|
|
|
|
* \section Function Names
|
|
|
|
*
|
|
|
|
* - `BKE_main_namemap_` Should be used for functions in this file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "BLI_compiler_attrs.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct ID;
|
|
|
|
struct Main;
|
|
|
|
struct UniqueName_Map;
|
|
|
|
|
|
|
|
struct UniqueName_Map *BKE_main_namemap_create(void) ATTR_WARN_UNUSED_RESULT;
|
|
|
|
void BKE_main_namemap_destroy(struct UniqueName_Map **r_name_map) ATTR_NONNULL();
|
|
|
|
|
2023-02-06 19:20:45 +01:00
|
|
|
/**
|
|
|
|
* Destroy all name_maps in given bmain:
|
|
|
|
* - In bmain itself for local IDs.
|
|
|
|
* - In the split bmains in the list is any (for linked IDs in some cases, e.g. if called during
|
|
|
|
* readfile code).
|
|
|
|
* - In all of the libraries IDs (for linked IDs).
|
|
|
|
*/
|
|
|
|
void BKE_main_namemap_clear(struct Main *bmain) ATTR_NONNULL();
|
|
|
|
|
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
2022-07-20 13:27:14 +02:00
|
|
|
/**
|
|
|
|
* Ensures the given name is unique within the given ID type.
|
|
|
|
*
|
|
|
|
* In case of name collisions, the name will be adjusted to be unique.
|
|
|
|
*
|
2023-07-16 07:50:02 +02:00
|
|
|
* \param do_unique_in_bmain: if `true`, ensure that the final name is unique in the whole Main
|
|
|
|
* (for the given ID type), not only in the set of IDs from the same library.
|
2023-07-08 16:16:49 +02:00
|
|
|
*
|
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
2022-07-20 13:27:14 +02:00
|
|
|
* \return true if the name had to be adjusted for uniqueness.
|
|
|
|
*/
|
2023-07-08 16:16:49 +02:00
|
|
|
bool BKE_main_namemap_get_name(struct Main *bmain,
|
|
|
|
struct ID *id,
|
|
|
|
char *name,
|
|
|
|
const bool do_unique_in_bmain) ATTR_NONNULL();
|
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
2022-07-20 13:27:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a given name from usage.
|
|
|
|
*
|
|
|
|
* Call this whenever deleting or renaming an object.
|
|
|
|
*/
|
|
|
|
void BKE_main_namemap_remove_name(struct Main *bmain, struct ID *id, const char *name)
|
|
|
|
ATTR_NONNULL();
|
|
|
|
|
2022-07-27 11:19:48 +02:00
|
|
|
/**
|
|
|
|
* Check that all ID names in given `bmain` are unique (per ID type and library), and that existing
|
|
|
|
* name maps are consistent with existing relevant IDs.
|
|
|
|
*
|
|
|
|
* This is typically called within an assert, or in tests.
|
|
|
|
*/
|
|
|
|
bool BKE_main_namemap_validate(struct Main *bmain) ATTR_NONNULL();
|
|
|
|
|
2023-05-27 07:10:58 +02:00
|
|
|
/**
|
|
|
|
* Same as #BKE_main_namemap_validate, but also fixes any issue by re-generating all name maps,
|
2022-07-27 15:29:49 +02:00
|
|
|
* and ensuring again all ID names are unique.
|
|
|
|
*
|
|
|
|
* This is typically only used in `do_versions` code to fix broken files.
|
|
|
|
*/
|
|
|
|
bool BKE_main_namemap_validate_and_fix(struct Main *bmain) ATTR_NONNULL();
|
|
|
|
|
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
2022-07-20 13:27:14 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|