Regression: Creating material node links in python is VERY slow in v3.1 #97375
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#97375
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Windows-10-10.0.19043-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 496.49
Blender Version
Broken: version: 3.1.0, branch: master, commit date: 2022-03-08 18:16, hash:
c77597cd0e
Regression is caused by
7e712b2d6a
Short description of error
Node trees for materials and other can be edited and created in python by using the node_tree.nodes and node_tree.links data sets. Creating new links via node_tree.links.new() function call in python is now 7000x times slower than in previous versions of Blender. This makes programmatically creating complicated materials with many node links practically impossible as it takes far too long to ever create them (it is probably actually faster to do so by hand through the UI?!).
Exact steps for others to reproduce the error
Simply use the python interface to create a link between two nodes via node_tree.links.new() and compare time it takes with other versions.
Added subscriber: @JerahmyPocott
Added subscriber: @HooglyBoogly
Changed status from 'Needs Triage' to: 'Needs User Info'
Thanks for the report. Could you upload a simple test file with the script you described? It's helpful to have an exact file to make talking about things easier.
'Simple' is a bit of a problem, since it has to be a reasonably complex node tree for it to become noticeable.
In simple tests 3.1 actually handles larger node trees faster than 3.0 by a significant margin.
But when I use an actual production shader being run through this script which in this case will create 1015 links, Blender 3.1 takes 4 MINUTES to complete the links, while Blender 3.0 takes 15 seconds doing the exact same task.
This leads me to think it must be incorrectly recompiling the shader between linking or some similarly time consuming task.
I've written a simple test script that will trigger the problem when run with the right material (but do you really want an 800 node material that triggers the problem? because thats what I've got):
linknodetest.blend
I've packaged the script along with a material into a blend file. The material is just some nodes I culled from a much larger shader, but it demonstrates the performance issue even though it doesn't do anything. When testing this on my machine the scirpt takes around 5 seconds to complete on Blender 3.1, vs a few ms to complete on Blender 3.0.
The performance difference quickly scales up if you add more nodes, the full shader takes over 4 minutes, vs 15 seconds.
Changed status from 'Needs User Info' to: 'Confirmed'
Thanks for the details. I can confirm the subpar performance.
Added subscribers: @JacquesLucke, @lichtwerk
Regression is caused by
7e712b2d6a
Will raise prio since it is a recent regression, feel free to lower if this does not feel appropriate.
CC @JacquesLucke
Creating material node links in python is VERY slow in v3.1to Regression: Creating material node links in python is VERY slow in v3.1While there are certainly ways to reduce the constant overhead a bit (by e.g. computing
create_identifier_map
lazily), the real problem here is that the entire node tree update function has to be run after each added link. This is an algorithmic complexity problem. The code would probably run pretty much in an instant if we had a method in python that would allow adding multiple links in one call.Added subscriber: @LazyDodo
This issue existed in different forms for a long long time, I tried adding a batch update that just suppressed updates in D2691 which brought one of my scripts down from 20 minutes to a few seconds, but that didn't make it through review, I would expect a single call to have even better performance since it's not tripping in between python and C for every node you add.
OK, OK, so this was never particularly fast, but it got 7000x times slower in 7e712b2d6a...
no-ones arguing that, the point I was trying to make was : the proposed solution will likely have satisfactory performance
While previous performance wasn't great, it was mostly acceptable. So, in lieu of a better solution returning to previous performance levels would be satisfactory. Yes it still takes 30s to do what should really take 30ms, but that is still a lot better than taking 30 minutes.
This issue was referenced by
54b293237e
Changed status from 'Confirmed' to: 'Resolved'
54b293237e
makes it quite a bit faster for me. Might still be slower than before but maybe it's usable enough for your use case. If it's still wayyyy to slow, please make a new report with a new test file that allows us to reproduce the issue easily.