Speed up the execution
Created by: JacquesLucke
Hi, I just browsed a bit through your code and found something that really slows down the node tree execution. While I speeded up the Animation nodes I noticed that everytime I call socket.links, internally it iterates through every link in the node tree. (I actually found the code where this happens but forgot where it is). [EDIT] found the line: https://developer.blender.org/diffusion/B/browse/master/release/scripts/modules/bpy_types.py;e43c5fa005c941aa773f35fb6b8398afe37b25e9$816 [/EDIT]
This seams like a small thing but the effect of changing these lines is huge. By removing this in several areas in my kernel the script generation progress became around 10 times faster! And here you seam to call this in every single node. this is one example commit of 5 or so: https://github.com/JacquesLucke/animation-nodes/commit/399dae85aaae38c395879361d0df0437bb5b15d1
The trick I used is that everytime I need to know where the data comes from I iterate through all the links myself AND write the 'origin sockets' in a dictionary.
https://github.com/JacquesLucke/animation-nodes/blob/master/mn_network_code_generator.py#L554-L593
You just have to be sure that you clear this dictionary after one update process. Otherwise Blender can easily crash. This method also help to deal with Reroute nodes, because a function can define where the data comes from instead of the actual link. I do this here: https://github.com/JacquesLucke/animation-nodes/blob/master/mn_utils.py#L115-L126
I hope that helps to improve the performance. btw: the good thing is that this is only a back-end change (an additional abstraction layer), so it is 100% compatible with existing nodes. Another good thing is that you can do this change step by step. No need to do a whole rewrite until it works again.