Material node creation call slows down with node count

While trying to create material nodes through python script (node_tree.nodes.new), I found that as the node count increases, node creation process slows down. My questions: 1) Is there a limit on the number of material nodes in the node tree and 2) Are there ways to speed up the process of node creation even with high count of existing nodes in the tree.

My advice is – create node groups for sub-sections of the node-graph. Node groups are in their own trees, so the lookup time should be managable in each one. This will also make it easier to read in the UI.

1 Like

About your first question. Blender doesn’t have a hard limit on the number of nodes. But for example with material nodes you could detect a limitation within specific GPU drivers when they are compiling the shader.

Have you a script that shows this slow down or have you attached a profiler to see where the bottleneck is? That might help understanding what is going on or at least provided the data we could give you better answers.

@JeroenBakker I wouldn’t be surprised if nothing changed in this area since i posted D2691 in 2017

@JeroenBakker
I have written a script (add-on) that generates nodes from text expressions (https://github.com/Shriinivas/xnodify). Using that, I am trying to create texture from curve, by splitting the curve into straight line segments. When the number of segments in the curve grow, there is a sharp increase in time required for node creation. Attaching the stats of node count versus time taken for a single call to nodes.new.

The blende file is uploaded here:

largeNodeCnt.txt (216.2 KB)

@Josephbburg
Thanks for the suggestion. I had thought of this, but there are a couple of problems with using node group in this particular case. Firstly, there seems to be no way of creating a group out of existing nodes (except a call to bpy.ops.node.group_make()). The nodes can be grouped only by creating a group first and then using the node_tree of the group for creating the member nodes. This puts a lot of limitations when creating node groups from script.
And secondly, even with a call to bpy.ops.node.group_make(), there doesn’t seem to exist any way to tweak the sockets of Group Output and Group Input nodes for interfacing the inside nodes with the outside ones. Maybe I am missing something here. But since bpy.ops itself is likely to introduce performance issues, I did not pursue this approach any further.

I know Sorcar uses the bpy.ops calls to do its node-groups. You might have a look at their code, or Sverchok. Not many node addons have nodegroups, though. I don’t think LuxCore does.

Anyways, I’m confident that there’s a way to do it. I think I’ve done it myself in the past. If you can’t figure it out by looking at their code then I can try and figure it out.

1 Like