From fbf5b27b7ecc80710154604224d899fe38d7ffdc Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Wed, 5 Sep 2018 11:07:47 +0100 Subject: [PATCH] perf: faster startup time I noticed that libp2p takes over 200ms to require. When using the CLI with no daemon we never start the IPFS node so libp2p is required but unused. This PR lazily requires libp2p when start is called, which means that if the node is never started, you do not suffer the 200ms it takes to require the library. License: MIT Signed-off-by: Alan Shaw --- src/core/components/libp2p.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/components/libp2p.js b/src/core/components/libp2p.js index c07e7b79f0..87838cb1e7 100644 --- a/src/core/components/libp2p.js +++ b/src/core/components/libp2p.js @@ -1,7 +1,5 @@ 'use strict' -// libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified -const Node = require('../runtime/libp2p-nodejs') const promisify = require('promisify-es6') const get = require('lodash/get') const defaultsDeep = require('@nodeutils/defaults-deep') @@ -59,6 +57,9 @@ module.exports = function libp2p (self) { libp2pDefaults ) + // Required inline to reduce startup time + // Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified + const Node = require('../runtime/libp2p-nodejs') return new Node(libp2pOptions) }