Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Expression optimization – are values ever cached?

  • Expression optimization – are values ever cached?

    Posted by Noel Powell on August 2, 2025 at 5:09 pm

    Perhaps someone can settle this for me. ChatGPT and Gemini are giving me conflicting answers, but it looks like I may have been writing expressions wrong for years…

    Let’s say I have a ton of layers with a Position expression. A chunk of the expression calculates the same value on every layer. Normally, I would put that chunk on a separate slider on a Control Layer, and then reference that value in each expression. Is that more efficient, or does that take even longer because After Effects has to call up that other layer, plus recalculate that chunk of code each time anyway?

    And if values aren’t cached across layers, what about across properties? Like, if multiple expressions on a single layer all have the same chunk of code. Does it make sense to put that on a separate slider, if it’s on that same layer?

    Thanks in advance

    Roland R. kahlenberg replied 8 months, 3 weeks ago 2 Members · 7 Replies
  • 7 Replies
  • Roland R. kahlenberg

    August 7, 2025 at 7:32 pm

    I’ve got a blog on this – https://www.broadcastgems.com/post/how-to-write-performant-expressions-in-adobe-after-effects-developing-intelligent-bespoke-motion

  • Noel Powell

    August 7, 2025 at 8:17 pm

    Very helpful, thank you! The posterizeTime(0) trick was new to me and will come in handy.

    I’m trying to understand how your 0% Opacity suggestion works, though. Because I can clearly see After Effects making the calculations when the layer is at 0%, or even disabled with the eye icon. If you scrub through, the values of expression driven properties still change. Is it treated differently when it’s actually previewing or rendering, than when scrubbing through?

  • Roland R. kahlenberg

    August 8, 2025 at 10:30 am

    You’re welcome.

    On the Opacity setting, I use the Render Time column in the timeline to do my checks – it’s supposed to be accurate AFAIK to check if processing is being done to a layer. How are you doing your checks?

  • Noel Powell

    August 8, 2025 at 1:20 pm

    For my current project, I’ve been using my phone’s stopwatch to time a cache/preview of the timeline. Then I’ll make my adjustments and time it again. I find the Render Time column inconsistent and pretty useless. I think it’s been more helpful to me in the past for comparing layers with lots of effects. But in this project, I have 100 identical layers with identical expressions, and the render times for each layer varies wildly – from layer to layer, as well as from frame to frame. And the total Frame Render Time is all over the place as well, ranging from 20ms to 1 sec per frame. Timing a preview of a 10-second section at least gives me the results I expect after making changes/improvements to the code.

  • Roland R. kahlenberg

    August 9, 2025 at 10:09 am

    The issue with inconsistent results is with AE using its cached results. So, the best tests are those that start off fresh, with no cached data – purging cache data prior to starting a preview is a good starting point for conducting tests.

    BTW, do your Expressions use the valueAtTime() method? And is there a reason not to bake the Expressions into keyframes or even perhaps to just use keyframes instead of Expressions? I’m asking because I’m working on a script that works well with lots of layers and keyframes.

  • Noel Powell

    August 9, 2025 at 3:12 pm

    I just emptied my disk cache and media cache to see what kind of difference it makes in the Render Time column. The “Frame Render Time” displays anywhere from 20ms to 1 second, and everywhere in between – both when I preview and pause, or jump to a random frame. I have always experienced that kind of inconsistency, so I’m surprised that you find it to be accurate. I am using valueAtTime(), and customizability through controls is important to me, so there’s not a lot of keyframing. Typically when I’m testing speed, I change the random seed and then move my render area far up the timeline to an area that’s not cached, then immediately start timing it. I guess I like this method because it gives me an average speed of all the frames. I feel like the Render Time column should work that way, but it doesn’t appear to.

  • Roland R. kahlenberg

    August 13, 2025 at 3:29 pm

    Render Time is not accurate – agreed – too many dynamic variables at play but it is a quick way to for identifying bottlenecks.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy