ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Expressions efficiency

COW Forums : Adobe After Effects

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Eddy Loonstijn
Expressions efficiency
on Jul 17, 2017 at 5:33:30 am

Many, many layers with expressions make my AE project very slow.
Is AE always evaluating all the expressions?
If I disable a layer with expression is AE stil evaluating this later?
Are there tricks & tips for making more efficiënt project using expressions?
Greetings, Eddy


Return to posts index

Leopoldo Perizzolo
Re: Expressions efficiency
on Aug 26, 2017 at 3:32:06 pm

AE computes only the value of expression that have not been calculated yet; after all expression of a specific keyframe has been calculated, it stops computing and outputs the value (unless its value depends upon other frames of the comp, such as if you use valueAtTime() ).

When an expression is turned off (the little Equals " = " sign becomes Not equals " ≠ "), it's no longer being processed by AE; you can get a proof of that when you accidentally have an error such as a division by 0 and the expression gets turned off automatically: the project file does not freeze trying to compute what the result might be, as it's being disabled.


I don't think there are lots of trick involved...the basic rules of thumb are:
1. keep you expressions as compact as possible (meaning try to avoid repeating sections of code that change very little), which leads me to point 2:
2. use functions whenever an operation has to be shared across multiple iterations of a piece of code;
3. some methods are more CPU/GPU intensive than others; one of the most intensive being sampleImage; be sure not to have multiple layers or expressions that use it.
4. generally speaking, "if" statements take less time than math functions; that is, unless you have to call bigger functions to compare two or more values while you could use already calculated variables.
5. speaking of multiple if statements (e.g. if((A && B) || (C && D)){} ), try to use the java "short-circuit" capability: basically, in every if/for/while statement always put first the comparison that it's more likely to prevent the if statement to be executed (e.g. if you know that the value G is 99% of the time = 0, a if statement should be constructed as follows: if(G == 1 && banana == 1); since G is probably 0, the program will skip the second comparison).

I think that's it! Hope it helps solve your problems.

Leopy


Return to posts index

Eddy Loonstijn
Re: Expressions efficiency
on Sep 3, 2017 at 9:35:46 pm

Thank you for your answer.
It certainly will help me to be more efficient with my many expressions.
BTW I think that functions are only practical, so you don't have to write so much code, but the program will for sure read all the code within the function all the times that it is called.
Your remark about the way to use if-statments is very to the point. In that way I can let AE skip many codelines that are on that moment not relevant.
Thanks again, Eddy


Return to posts index


Leopoldo Perizzolo
Re: Expressions efficiency
on Sep 8, 2017 at 10:57:25 am

Yes, you're right about functions. I forgot that we weren't talking also about memory consumption, since it's irrelevant in such applications. Yet, functions can still be useful when you do have repeating sections of code or to make operations clearer to understand, and also because when you have to apply changes to a piece of code, since you don't have duplicates, you only have to do it once and you get a lower risk of errors.

Leopy


Return to posts index

Leopoldo Perizzolo
Re: Expressions efficiency
on Sep 10, 2017 at 9:43:17 am

Yes, you're right about functions. I forgot that we weren't talking also about memory consumption, since it's irrelevant in such applications. Yet, functions can still be useful when you do have repeating sections of code or to make operations clearer to understand, and also because when you have to apply changes to a piece of code, since you don't have duplicates, you only have to do it once and you get a lower risk of errors.

Leopy


Return to posts index

Eddy Loonstijn
Re: Expressions efficiency
on Sep 11, 2017 at 7:00:18 am

Hi Leopold again,
I totally agree with your statements about functions.
Concerning the efficiency of expressions, I have adopted a new way of programming with expressions:
First, I just make the code (if possible with functions ;-))
Second, I look for a condition for the expression in the greater context and code an if-statement for this condition, so that the expression code is only 'under condition' evaluated.
Greetings, Eddy


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]