Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Do expression-generated values get cached?

Explorer ,
May 30, 2016 May 30, 2016

Does anyone know if the output values generated though an expression get cached for the frame like the rendered image does?

Meaning, does it make any improvement in speed to reference an expression value from the same frame as opposed to calculating it on each frame.

As a simplified example, say I have a slider-value-based expression with some heavy calculation that doesn't change through time. Does it improve expression calculation speed to call the resulting value from a single point in time (such as time=0), as opposed to calling it from the current time, which certainly recalculates on each frame?

TOPICS
Expressions
829
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , May 30, 2016 May 30, 2016

No. Expressions are always evaluated for each frame and looking up values from a different time in fact makes matters worse since AE may evaluate the expression on the current frame and then based on the code evaluate it again on the other frame. AE simply has no way of differentiating the state of an expression unless it actually evaluates just like it doesn't store persistent values, doesn't do JIT compiling or whatever other thing you could imagine. It's a strictly linear script evaluation fr

...
Translate
LEGEND ,
May 30, 2016 May 30, 2016

No. Expressions are always evaluated for each frame and looking up values from a different time in fact makes matters worse since AE may evaluate the expression on the current frame and then based on the code evaluate it again on the other frame. AE simply has no way of differentiating the state of an expression unless it actually evaluates just like it doesn't store persistent values, doesn't do JIT compiling or whatever other thing you could imagine. It's a strictly linear script evaluation frame by frame and line by line, so optimizing it depends on structuring the code and the project structure. Of course nothing stops you from outsourcing code to "inert" invisible layers or comps not used anywhere, but this has other repercussions in case your calculations are dependent on time or layer order. If things get too slow, you can also always convert the expression to keyframes.

Mylenium

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 30, 2016 May 30, 2016
LATEST

Thanks Mylenium, good to know.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 30, 2016 May 30, 2016

Apparently, valueAtTime(t) behaves differently according to what property it refers to.

If it is another property (than the one hosting the expression), it will be the post-expression value of that property

And if it is the property hosting the expression, it will be the pre-expression value of the hosting property.

I dont know whether it is mentionend somewhere, but you can check it with a setup like this: slider with no keyframe, value at 0, and an expression like:

"if (time<=0) 0 else 1+valueAtTime(time-thisComp.frameDuration);"

If the expression was retrieving the postexpression value, the slider postexpression value would be increasing by 1 at everyframe. But it isnt.

So an expression on a property is only aware of key values on the hosting property. Don't know if this helps...

Xavier

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines