Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit dcf2e8e

Browse files
authored
fix: remove it-pipe (#69)
Every iteration of every pipeline function in `it-pipe` crosses an async boundary so it can harm performance if your pipleline would otherwise be synchronous. Fixes #44
1 parent ac2f065 commit dcf2e8e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@
158158
"it-filter": "^2.0.0",
159159
"it-foreach": "^1.0.0",
160160
"it-map": "^2.0.0",
161-
"it-pipe": "^2.0.3",
162161
"mortice": "^3.0.0",
163162
"multiformats": "^11.0.0",
164163
"protons-runtime": "^5.0.0",

src/address-book.ts

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import { CodeError } from '@libp2p/interfaces/errors'
33
import { isMultiaddr } from '@multiformats/multiaddr'
44
import { codes } from './errors.js'
55
import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record'
6-
import { pipe } from 'it-pipe'
7-
import all from 'it-all'
8-
import filter from 'it-filter'
9-
import map from 'it-map'
10-
import each from 'it-foreach'
116
import { peerIdFromPeerId } from '@libp2p/peer-id'
127
import { CustomEvent } from '@libp2p/interfaces/events'
138
import type { Address, AddressFilter, Peer, PeerMultiaddrsChangeData, PeerStore } from '@libp2p/interface-peer-store'
@@ -346,21 +341,27 @@ export class PeerStoreAddressBook {
346341
}
347342

348343
async function filterMultiaddrs (peerId: PeerId, multiaddrs: Multiaddr[], addressFilter: AddressFilter, isCertified: boolean = false): Promise<Address[]> {
349-
return await pipe(
350-
multiaddrs,
351-
(source) => each(source, (multiaddr) => {
344+
const output: Address[] = []
345+
346+
await Promise.all(
347+
multiaddrs.map(async multiaddr => {
352348
if (!isMultiaddr(multiaddr)) {
353349
log.error('multiaddr must be an instance of Multiaddr')
354350
throw new CodeError('multiaddr must be an instance of Multiaddr', codes.ERR_INVALID_PARAMETERS)
355351
}
356-
}),
357-
(source) => filter(source, async (multiaddr) => await addressFilter(peerId, multiaddr)),
358-
(source) => map(source, (multiaddr) => {
359-
return {
352+
353+
const include = await addressFilter(peerId, multiaddr)
354+
355+
if (!include) {
356+
return
357+
}
358+
359+
output.push({
360360
multiaddr,
361361
isCertified
362-
}
363-
}),
364-
async (source) => await all(source)
362+
})
363+
})
365364
)
365+
366+
return output
366367
}

0 commit comments

Comments
 (0)