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

perf: lazy load IPLD formats #1704

Merged
merged 2 commits into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,11 @@
"ipfs-repo": "~0.25.0",
"ipfs-unixfs": "~0.1.16",
"ipfs-unixfs-engine": "~0.33.0",
"ipld": "~0.19.1",
"ipld": "~0.19.3",
"ipld-bitcoin": "~0.1.8",
"ipld-dag-pb": "~0.14.11",
"ipld-ethereum": "^2.0.1",
"ipld-git": "~0.2.2",
"ipld-raw": "^2.0.1",
"ipld-zcash": "~0.1.6",
"ipns": "~0.3.0",
"is-ipfs": "~0.4.7",
Expand Down
59 changes: 39 additions & 20 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ const debug = require('debug')
const extend = require('deep-extend')
const EventEmitter = require('events')

// All known IPLD formats
const ipldBitcoin = require('ipld-bitcoin')
const ipldDagCbor = require('ipld-dag-cbor')
const ipldDagPb = require('ipld-dag-pb')
const ipldEthAccountSnapshot = require('ipld-ethereum').ethAccountSnapshot
const ipldEthBlock = require('ipld-ethereum').ethBlock
const ipldEthBlockList = require('ipld-ethereum').ethBlockList
const ipldEthStateTrie = require('ipld-ethereum').ethStateTrie
const ipldEthStorageTrie = require('ipld-ethereum').ethStorageTrie
const ipldEthTrie = require('ipld-ethereum').ethTxTrie
const ipldEthTx = require('ipld-ethereum').ethTx
const ipldGit = require('ipld-git')
const ipldRaw = require('ipld-raw')
const ipldZcash = require('ipld-zcash')

const config = require('./config')
const boot = require('./boot')
const components = require('./components')
Expand All @@ -39,6 +24,40 @@ const defaultRepo = require('./runtime/repo-nodejs')
const preload = require('./preload')
const mfsPreload = require('./mfs-preload')

// All known (non-default) IPLD formats
const IpldFormats = {
get 'bitcoin-block' () {
return require('ipld-bitcoin')
},
get 'eth-account-snapshot' () {
return require('ipld-ethereum').ethAccountSnapshot
},
get 'eth-block' () {
return require('ipld-ethereum').ethBlock
},
get 'eth-block-list' () {
return require('ipld-ethereum').ethBlockList
},
get 'eth-state-trie' () {
return require('ipld-ethereum').ethStateTrie
},
get 'eth-storage-trie' () {
return require('ipld-ethereum').ethStorageTrie
},
get 'eth-tx' () {
return require('ipld-ethereum').ethTx
},
get 'eth-tx-trie' () {
return require('ipld-ethereum').ethTxTrie
},
get 'git-raw' () {
return require('ipld-git')
},
get 'zcash-block' () {
return require('ipld-zcash')
}
}

class IPFS extends EventEmitter {
constructor (options) {
super()
Expand Down Expand Up @@ -99,11 +118,11 @@ class IPFS extends EventEmitter {
this._blockService = new BlockService(this._repo)
this._ipld = new Ipld({
blockService: this._blockService,
formats: [
ipldBitcoin, ipldDagCbor, ipldDagPb, ipldEthAccountSnapshot,
ipldEthBlock, ipldEthBlockList, ipldEthStateTrie, ipldEthStorageTrie,
ipldEthTrie, ipldEthTx, ipldGit, ipldRaw, ipldZcash
]
loadFormat: (codec, callback) => {
this.log('Loading IPLD format', codec)
if (IpldFormats[codec]) return callback(null, IpldFormats[codec])
callback(new Error(`Missing IPLD format "${codec}"`))
}
})
this._preload = preload(this)
this._mfsPreload = mfsPreload(this)
Expand Down