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

Commit 2790e6d

Browse files
authored
perf: faster startup time (#1542)
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 <[email protected]>
1 parent 7c7a5a6 commit 2790e6d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/core/components/libp2p.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict'
22

3-
// libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
4-
const Node = require('../runtime/libp2p-nodejs')
53
const promisify = require('promisify-es6')
64
const get = require('lodash/get')
75
const defaultsDeep = require('@nodeutils/defaults-deep')
@@ -59,6 +57,9 @@ module.exports = function libp2p (self) {
5957
libp2pDefaults
6058
)
6159

60+
// Required inline to reduce startup time
61+
// Note: libp2p-nodejs gets replaced by libp2p-browser when webpacked/browserified
62+
const Node = require('../runtime/libp2p-nodejs')
6263
return new Node(libp2pOptions)
6364
}
6465

0 commit comments

Comments
 (0)