Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
perf: faster startup time (#1542)
Browse files Browse the repository at this point in the history
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 <alan@tableflip.io>
  • Loading branch information
alanshaw authored Sep 12, 2018
1 parent 7c7a5a6 commit 2790e6d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/components/libp2p.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 2790e6d

Please sign in to comment.