From 49cebf497ce02f6d04b64377e5d487458fb0860f Mon Sep 17 00:00:00 2001 From: Zach Bjornson Date: Thu, 4 Apr 2019 19:06:19 -0700 Subject: [PATCH] lazy-load simple-get Appears to save ~1.5-2 MB of memory and improves startup speed. --- lib/image.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/image.js b/lib/image.js index f51c702c3..2788a5d93 100644 --- a/lib/image.js +++ b/lib/image.js @@ -12,9 +12,11 @@ const bindings = require('./bindings') const Image = module.exports = bindings.Image -const get = require('simple-get') const util = require('util') +// Lazily loaded simple-get +let get; + const {GetSource, SetSource} = bindings; Object.defineProperty(Image.prototype, 'src', { @@ -45,6 +47,8 @@ Object.defineProperty(Image.prototype, 'src', { } } + if (!get) get = require('simple-get'); + get.concat(val, (err, res, data) => { if (err) return onerror(err)