How to Write Performant Expressions in Adobe After Effects - developing intelligent, bespoke Motion-Brand Toolkit Systems
- Roland Kahlenberg
- Apr 13
- 6 min read
Updated: 5 days ago
After Effects processes each Expression on every frame - understanding this and other important bits of information will help you write Expressions that are more performant; leading to better user-experiences for your users and this includes yourself.
When developing bespoke Intelligent Design Assets (AE Templates with Responsive and Adaptive features), you're going to be dealing with lots of Expressions - anywhere between 8 up to a hundred, or more, Expressions in your Timeline.
If you don't know how to write performant Expressions then chances are you won't attempt developing such Systems or you would stop midway because you know it's going to be too slow for use in the real world by demanding clients.
But if you love Motion Design and especially so for its use in the world of Branding and/or Creative Automation then you really need to get up to speed. Fortunately, it's not a tall hurdle to climb - it's a lot of common sense and not being lazy.
Canva, Adobe Express and other niche SaaS provide template-based creative solutions and it's a huge market. You won't survive for long if you develop basic ordinary Motion Templates because these sites provide excellent template designs and include automated translation and easy scaling of output by allowing its users to hook up the designs to a spreadsheet. In short, they can do a lot and their platforms are superfast.
If you are going to stick in the niche market place, you have to be near the top of the game with your Expressions, Designs, Kinetic Typography, Shape Layers, Cinematography and the list goes on.
I am hopeful you take away and practice these simple-to-apply guides so that you can practice your art and craft as best as you can.
Addendum
Layer Opacity - When a layer's Transform > Opacity is 0, After Effects skips calculations for the layer. This obviously saves a lot of time, especially when developing Intelligent Design Assets where you will have more layers available than required at any point in time.
So, only subset of layers are enabled and this set of layers change depending on user-selections or automated selections. Hence, by setting non-active layers' Tranform > Opacity to 0 is an excellent way to speed up After Effects.
Glossary of Key Terms
Performant Code: Code that executes calculations quickly and efficiently, minimizing processing time.
Optimizing Code Structure: Organizing and arranging code in a way that is efficient for the software to process, often involving minimizing redundancy and streamlining and directing logic.
Modern JavaScript: Refers to newer features, syntax, and built-in functions and methods introduced in recent ECMAScript specifications, often designed for improved readability and performance.
Legacy Methods/Algorithms: Older ways of writing code to achieve certain tasks, which might be less efficient or more verbose compared to modern JavaScript approaches.
Conditional Logic: A common programming construct that uses statements such as "if ... else" or the Ternary Conditional to execute based on whether one or more conditions is true or false.
posterizeTime(0): An After Effects Expression method that forces a property to hold the same value for the entire duration of the composition, based on calculations performed at the first frame (time = 0). Writing posterizeTime() without the 0 also works.
valueAtTime(): An After Effects expression method that returns the value of a property at a specific time.
tryCatch Statement: A JavaScript construct used for error handling, allowing code to attempt an operation and gracefully handle any errors that occur.
Lean Deliverables: Final project files or templates that are optimized for performance and do not contain unnecessary elements or code that hinders performance. During the Development Stage, there will be Helper Properties, Effects and Layers used to help test certain calculations and scenarios or to store values temporarily. These form the bulk of what is to be removed in Deliverables.
And when developing using a Design System that uses a Token System, it is expected to start the development process with a Development Template which will most likely contain more layers and properties that will eventually be used.
Reproducible Code: Code that, when duplicated along with its containing object (leveraging After Effects' automatic numbered suffix naming), automatically adapts its references to the newly created duplicate.
Referenced Object: Another layer or property within the After Effects project that an Expression accesses and uses in its calculations.
Questions: Performant After Effects Expressions
1. What does "performant code" mean in the context of After Effects Expressions, and why is it important?
Performant code in After Effects Expressions refers to code that executes calculations as quickly as possible. This is crucial for ensuring quick previews and positive user-experiences. Delivering a lean and performant final product is also essential for a positive client experience.
And if you develop Toolkits or other Motion Systems, you can take matters further and add Responsive and Adaptive features which allows the user to work with a much smaller set of deliverables while allowing for even more output options.
2. How does the structure of my Expression code impact its performance?
Keeping multiple calculations within a single Expression is more performant than referencing multiple properties where each property's Expression performs its own calculations.
When an Expression references multiple properties, you should carefully consider whether to consolidate the Expression/calculation in these properties into the current Expression or to reference these properties' Expression.
For each Expression/Property After Effects references, it has to leave the current Expression, traverse to the referenced Expression/Property, compute the Expression there and then return to the current Expression. This moving away and back takes extra time and should form part of your decision process.
Your final decision depends on the added complexity to the current Expression after you consolidate these Expressions. Additionally, if other Expressions perform consolidation of these same Expressions then anytime you have to update one of these consolidated calculations, you have to update other Expressions as well.
So, while it is indeed more performant to have all calculations performed within a single Expression, if there are smaller calculations that are also used by other Expressions, it may actually be a smarter decision to split up the calculations into individual properties so that updating it once will allow other Expressions referencing it to also update automatically.
3. How can I optimize conditional logic (if-else statements) in my Expressions for better performance?
When using Conditional Statements, prioritize checking for the most likely or frequently occurring conditions first. This allows the Expression to exit the conditional blocks more quickly, to perform other calculations and logical reasoning in the Expression.
Additionally, if a condition must be met for calculations to proceed, check for this condition as early as possible in the Expression to avoid unnecessary computations. While it might be tempting to check conditions outside the current property or layer, carefully weigh the performance cost of this check against the potential time saved by skipping calculations.
4. When and how should I declare variables and their references in my Expressions?
Declare variables and their references only when they are actually needed within the Expression's logic. Avoid declaring all variables at the beginning if only a few are used under specific conditions.
Another consideration is If a referenced property is used multiple times within an Expression - in such situations, declare a variable for the referenced property to allow After Effects to cache the reference and to re-use it quickly as and when is required within the rest of the Expression.
5. What is posterizeTime(0) and how can it be used to enhance Expression performance? Are there any limitations to its use?
posterizeTime(0) is a Expression Method that, when placed as the first line of an Expression, tells After Effects to calculate the Expression only on the first frame of the composition. This significantly improves performance for properties that do not need to animate over time, such as static anchor points or positions. However, posterizeTime(0) should not be used on properties that are intended to animate or if the Expression references an animating property. Although the calculation happens only once at Time=0, the Expression can still access values of other properties at times other than 0, in its calculations.
6. What alternatives to posterizeTime(0) can I consider for performance optimization when dealing with animated properties?
If you cannot use posterizeTime(0) because the property with the Expression is animating or if it's not animating but it is referencing a property that is animating, consider using the valueAtTime() method to calculate at a specific time or over a time span.
7. What considerations should I keep in mind regarding referenced properties and delivering a lean final product?
When your expression references other animated properties, be aware that these animations will still trigger expression evaluations on each frame, even if your expression itself is optimized. Before delivering a final project, it's important to remove any unnecessary elements used for testing or development, such as null objects, tryCatch statements, and potentially "Reproducible Code." While Reproducible Code can speed up prototyping by leveraging After Effects' automatic naming conventions during duplication, it introduces additional performance overhead and might be worth removing for the final deliverable.
8. How does using modern JavaScript features contribute to writing more performant After Effects Expressions?
Utilizing Modern JavaScript functions and methods can lead to more performant After Effects expressions. These newer features are often designed to solve common coding tasks more efficiently with fewer lines of readable code compared to older, more legacy approaches or custom algorithms. Taking advantage of Modern JavaScript can result in faster execution and more maintainable expressions.
Comments