Copy link to clipboard
Copied
Hello.
I have many layer with the same expression on their position property.
This expression repeats the same tasks(repeated code) for all the layers, which make the performance very slow.
My question is can I make a sudo effect (property) calculates the repeated code, and then just get a cached value for this property to the position properties and improve the performance?
I don't know if using propery.value uses some caching system or not.
I am using some heavy algorithems, so this will help me so much achieving what I need.
So I hope you help me acheive this😊🙏.
Thank you!
Copy link to clipboard
Copied
Hi Ahmed,
Looks like no one's answered your specific question just yet, but I did ask the product team about it, and I am awaiting an answer for you. In the meantime, you could check out this article on improving performance. https://adobe.ly/48Ri4q6. I hope it helps:
Thanks,
Kevin
Copy link to clipboard
Copied
This piece of information would really help me so much as an adobe extension developer.
I will wait for the answer😊🙏.
Copy link to clipboard
Copied
Any new peice of information?
Copy link to clipboard
Copied
No reponse yet. I'll ask again.
Thanks,
Kevin
Copy link to clipboard
Copied
Thanks for asking about this. I'm from the After Effects team—could you provide more information about your use case?
In general, yes, doing expensive calculations on a separate property that drives other properties can take advantage of a "pseudo" caching, but the caching in AE is more complex than "have I run this expression before?". Anytime that the expression contains calls out to other data or properties, which also may have changed, answering that question generally involves executing the expression again. Simple property links are generally cached, but values changing over time will have the same cache lifetime as rendered frames themselves.
Adding further complexity is that any expression which calls to another expression-driven property will require a new JS engine be spun up to evaluate that second expression. This can lead to stack overruns if that second expression calls another expression-driven property, etc. The best rule of thumb is to keep all expression references as O(1), since they are already running in a loop (once per frame) or use tricks like posterizeTime(0) to limit how many times an expression will execute.
Hope that is helpful,
- John, After Effects Engineering Team
Copy link to clipboard
Copied
Here is more information about my use case!
I am working on a tool to create grids and add items (layers) inside the grids' cells.
You can see some results in these videos:
video 1 video2
So, how this thing work exactly?
There is an expression on each layer's position and scale property that calculates the right place for the item each frame.
This expression actually the same code for all these layers.
The expression calculates all the positions for all the layer's and then picks the position of the current layers that is on.
The expression is not very fast, and calculating it for each item('layer) makes it even slower, it will be a major optimization if I could calculate this expression on a psudo effect, and we make the layers get the result array and get its position and scale values!
This picture here can impove the understanding of my case:
Copy link to clipboard
Copied
@JohnColombo Here?😊
Copy link to clipboard
Copied
Thanks for your patience, @ahmed hamed elsaid.
You will need to do some experimentation to see which approach will work best with your specific expression. As I mentioned, in some cases, each layer will still end executing the full calculation even in the "faster way" case you've visualized above due to the caching and expression engine complexities involved.
A better approach might be to write the "calc expression" itself to be O(1), e.g. each layer uses its own position or index relative to a single layer, input vaue, or controller to calculate it's own location, rather than needing to be aware of all others layers. Not every type of grid calculation will work in that way, however, so it will depend on your specific needs. This is generally how I've used expressions to create grids in the past.
Cheers,
- John, After Effects Engineering Team
Copy link to clipboard
Copied
calc expression is a huge code with 1000 line.
I can't make it O(1) like you said.
So, the answer is I can't cach expressions, because it will end always to execute the expression when calling?
Even when calling with valueAtTime(), or .value, won't make any difference?
No any way to avoid this and just getting the calculated value without executing the expression again?
Copy link to clipboard
Copied
As I mentioned, it will depend on your specific code so you will need to do some experimentation. Try using the Render Time column in the Timeline to see render times for performance comparisions. There is some caching, but I can't be sure it will apply to your use case.
- John, After Effects Engineering Team
Find more inspiration, events, and resources on the new Adobe Community
Explore Now