diff options
author | Aras Pranckevicius <aras@nesnausk.org> | 2022-07-23 15:16:14 +0300 |
---|---|---|
committer | Aras Pranckevicius <aras@nesnausk.org> | 2022-07-23 15:16:14 +0300 |
commit | 092732d1136cf4bed04f5dcb117e7f4a0df5fc0c (patch) | |
tree | 433f0cf1b19df939eee70851ad13033d9559e3d7 /source/blender/io/wavefront_obj/importer | |
parent | beb746135dbe0c5ca21c2334e7dc475f201ad71e (diff) |
IO: speed up import of large amounts of objects in USD/OBJ by pre-sorting objects by name
Previously, when creating "very large" (tens-hundreds of thousands)
amounts of objects, the Blender code that was ensuring name
uniqueness was the bottleneck. That got recently addressed (D14162),
however now sorting of IDs by their names is the remaining bottleneck.
Name sorting code in Blender is optimized for the pattern where names
are inserted in already sorted order (i.e. objects expect to get added
near the end of the list). By doing this pre-sorting of objects
intended to get created by an importer (USD and OBJ, in this patch),
this sorting bottleneck can be largely removed, especially with very
high object counts.
Windows, Ryzen 5950X, import times:
- OBJ, splash screen scene (26k objects): 22.0s -> 20.7s
- USD, Disney Moana scene (250k objects): 585s -> 82.2s (10 minutes -> 1.5 minutes)
Reviewed By: Michael Kowalski, Howard Trickey
Differential Revision: https://developer.blender.org/D15506
Diffstat (limited to 'source/blender/io/wavefront_obj/importer')
-rw-r--r-- | source/blender/io/wavefront_obj/importer/obj_importer.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/io/wavefront_obj/importer/obj_importer.cc b/source/blender/io/wavefront_obj/importer/obj_importer.cc index f2051d195c8..bb32776d2be 100644 --- a/source/blender/io/wavefront_obj/importer/obj_importer.cc +++ b/source/blender/io/wavefront_obj/importer/obj_importer.cc @@ -9,6 +9,7 @@ #include "BLI_map.hh" #include "BLI_math_vec_types.hh" #include "BLI_set.hh" +#include "BLI_sort.hh" #include "BLI_string_ref.hh" #include "BKE_layer.h" @@ -44,6 +45,15 @@ static void geometry_to_blender_objects(Main *bmain, /* Don't do collection syncs for each object, will do once after the loop. */ BKE_layer_collection_resync_forbid(); + /* Sort objects by name: creating many objects is much faster if the creation + * order is sorted by name. */ + blender::parallel_sort( + all_geometries.begin(), all_geometries.end(), [](const auto &a, const auto &b) { + const char *na = a ? a->geometry_name_.c_str() : ""; + const char *nb = b ? b->geometry_name_.c_str() : ""; + return BLI_strcasecmp(na, nb) < 0; + }); + /* Create all the objects. */ Vector<Object *> objects; objects.reserve(all_geometries.size()); |