[Bf-blender-cvs] [a812fe8ceb7] master: Nodes: use extern templates for socket declarations

Jacques Lucke noreply at git.blender.org
Sun Oct 3 16:06:22 CEST 2021


Commit: a812fe8ceb75fd2befe44a151f1e214f357c24c2
Author: Jacques Lucke
Date:   Sun Oct 3 16:05:19 2021 +0200
Branches: master
https://developer.blender.org/rBa812fe8ceb75fd2befe44a151f1e214f357c24c2

Nodes: use extern templates for socket declarations

The new socket declaration api generates a surprising amount
of symbols in each translation unit where it is used. This resulted
in a measurable compile time increase.

This commit reduces the number of symbols that are generated in
each translation unit significantly. For example, in
`node_geo_distribute_points_on_faces.cc` the number of symbols
decreased from 1930 to 1335. In my tests, this results in a 5-20%
compile time speedup when this and similar files are compiled
in isolation (measured by executing the command in `compile_commands.json`).

Compiling the distribute points on faces node sped up from ~2.65s to ~2.4s.

===================================================================

M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_node_declaration.hh
M	source/blender/nodes/NOD_socket_declarations.hh
A	source/blender/nodes/intern/extern_implementations.cc

===================================================================

diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index c487288bc75..276af617d1c 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -377,6 +377,7 @@ set(SRC
   texture/node_texture_util.c
 
   intern/derived_node_tree.cc
+  intern/extern_implementations.cc
   intern/geometry_nodes_eval_log.cc
   intern/math_functions.cc
   intern/node_common.cc
diff --git a/source/blender/nodes/NOD_node_declaration.hh b/source/blender/nodes/NOD_node_declaration.hh
index 5b8003a03de..aa01afc6a14 100644
--- a/source/blender/nodes/NOD_node_declaration.hh
+++ b/source/blender/nodes/NOD_node_declaration.hh
@@ -197,6 +197,7 @@ class SocketDeclarationBuilder : public BaseSocketDeclarationBuilder {
   {
     decl_->output_field_dependency_ = OutputFieldDependency::ForPartiallyDependentField(
         std::move(input_dependencies));
+    return *(Self *)this;
   }
 };
 
diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh
index 3f7f9e0414e..6eac77b1d6b 100644
--- a/source/blender/nodes/NOD_socket_declarations.hh
+++ b/source/blender/nodes/NOD_socket_declarations.hh
@@ -330,3 +330,24 @@ inline Texture::Texture() : IDSocketDeclaration("NodeSocketTexture")
 }
 
 }  // namespace blender::nodes::decl
+
+/* --------------------------------------------------------------------
+ * Extern template instantiations that are defined in `intern/extern_implementations.cc`.
+ */
+
+namespace blender::nodes {
+#define MAKE_EXTERN_SOCKET_DECLARATION(TYPE) \
+  extern template class SocketDeclarationBuilder<TYPE>; \
+  extern template TYPE::Builder &NodeDeclarationBuilder::add_input<TYPE>(StringRef, StringRef); \
+  extern template TYPE::Builder &NodeDeclarationBuilder::add_output<TYPE>(StringRef, StringRef);
+
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Float)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Int)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Vector)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Bool)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Color)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::String)
+MAKE_EXTERN_SOCKET_DECLARATION(decl::Geometry)
+
+#undef MAKE_EXTERN_SOCKET_DECLARATION
+}  // namespace blender::nodes
diff --git a/source/blender/nodes/intern/extern_implementations.cc b/source/blender/nodes/intern/extern_implementations.cc
new file mode 100644
index 00000000000..42d4b2878bc
--- /dev/null
+++ b/source/blender/nodes/intern/extern_implementations.cc
@@ -0,0 +1,34 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "NOD_socket_declarations.hh"
+
+namespace blender::nodes {
+#define MAKE_EXTERN_SOCKET_IMPLEMENTATION(TYPE) \
+  template class SocketDeclarationBuilder<TYPE>; \
+  template TYPE::Builder &NodeDeclarationBuilder::add_input<TYPE>(StringRef, StringRef); \
+  template TYPE::Builder &NodeDeclarationBuilder::add_output<TYPE>(StringRef, StringRef);
+
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Float)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Int)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Vector)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Bool)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Color)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::String)
+MAKE_EXTERN_SOCKET_IMPLEMENTATION(decl::Geometry)
+
+#undef MAKE_EXTERN_SOCKET_IMPLEMENTATION
+}  // namespace blender::nodes



More information about the Bf-blender-cvs mailing list