From f624d01cacf64ae8adc76231e2c8efa30fb71f33 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Mon, 23 Nov 2015 14:17:54 -0800 Subject: [PATCH] Make Style Interpolator Function Generation Lazy Summary: This code generation executes eagerly and these functions are fairly large and takes time to compile. However, I'm mostly doing this change because it significantly increases the Prepack binary file size. In theory, there might be a slight impact on the first use of these interpolators but I couldn't really tell. An alternative would be to create a factory that is called by the components at an appropriate time, or to just refactor the whole thing to use Animated. I didn't want to dig too deeply for a single component though. public Reviewed By: vjeux Differential Revision: D2687296 fb-gh-sync-id: 6fc8cdf54dfb6f0b50c11db973d67d114bbc7400 --- Libraries/Utilities/buildStyleInterpolator.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Libraries/Utilities/buildStyleInterpolator.js b/Libraries/Utilities/buildStyleInterpolator.js index fdb9653e8..1ff93d106 100644 --- a/Libraries/Utilities/buildStyleInterpolator.js +++ b/Libraries/Utilities/buildStyleInterpolator.js @@ -553,8 +553,15 @@ var createFunctionString = function(anims) { * object and returns a boolean describing if any update was actually applied. */ var buildStyleInterpolator = function(anims) { - return Function(createFunctionString(anims))(); + // Defer compiling this method until we really need it. + var interpolator = null; + function lazyStyleInterpolator(result, value) { + if (interpolator === null) { + interpolator = Function(createFunctionString(anims))(); + } + return interpolator(result, value); + } + return lazyStyleInterpolator; }; - module.exports = buildStyleInterpolator;