zapier-platform icon indicating copy to clipboard operation
zapier-platform copied to clipboard

perf(legacy-scripting-runner): Optimize LSR imports based on source

Open codebycaleb opened this issue 2 years ago • 2 comments

Legacy Scripting Runner scripts have some overhead due to the loading of modules that we provide globally (e.g. underscore, moment, etc.). If we optimize the heaviest hitters (moment, jquery, and zfactory), we can see noticeable speed savings (especially for legacy apps that don't use any scripting at all!).

You might notice that this PR doesn't optimize all of the modules we load - just the heaviest hitters. That's because loading some of these takes next to no time at all. Benchmark results from Hyperfine for requiring each one individually (tested against ./nothing.js, a file that consists of module.exports = {};):

Command Mean [ms] Min [ms] Max [ms] Relative
node test_require.js ./nothing 40.9 ± 1.6 35.8 43.7 1.00
node test_require.js zapier-platform-legacy-scripting-runner/atob 41.9 ± 1.7 37.0 44.3 1.03 ± 0.06
node test_require.js zapier-platform-legacy-scripting-runner/btoa 42.1 ± 1.9 37.6 49.2 1.03 ± 0.06
node test_require.js underscore 42.6 ± 1.9 37.7 46.2 1.04 ± 0.06
node test_require.js crypto 43.4 ± 2.0 40.0 52.7 1.06 ± 0.06
node test_require.js async 43.9 ± 1.8 40.2 47.2 1.08 ± 0.06
node test_require.js xmldom 44.7 ± 1.7 40.9 47.6 1.09 ± 0.06
node test_require.js moment-timezone 51.6 ± 1.6 48.2 55.2 1.26 ± 0.06
node test_require.js zapier-platform-legacy-scripting-runner/zfactory 143.7 ± 3.2 136.9 151.3 3.52 ± 0.16
node test_require.js zapier-platform-legacy-scripting-runner/$ 262.5 ± 7.0 255.2 271.7 6.43 ± 0.31

codebycaleb avatar May 20 '22 11:05 codebycaleb