fix: skip validation when encapsulating/decapsulating#420
Conversation
6977a41 to
df20b6b
Compare
Shifts validation to `validate` function which gives the user more control over when expensive validation operations take place. For example we currently run multiple regex passes over IP addresses when creating new multiaddrs which can cause CPU bottlenecks.
df20b6b to
ec0635f
Compare
|
Refs: ipshipyard/roadmaps#1 |
| @@ -0,0 +1,40 @@ | |||
| export const CODE_IP4 = 4 | |||
There was a problem hiding this comment.
Can you add an jsdoc comment here so someone else can understand how to check if these are valid or not? or how to add a new key in the future?
There was a problem hiding this comment.
I've added a regular comment, jsdoc would appear in the html docs for the closest symbol so would need to be duplicated for every exported code.
| export { MultiaddrFilter } from './filter/multiaddr-filter.js' | ||
|
|
||
| /** | ||
| * @deprecated DNS resolving will be removed in a future release |
| function bench (m: typeof multiaddr | typeof multiaddr12): void { | ||
| const ma = m('/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/uEiAkH5a4DPGKUuOBjYw0CgwjvcJCJMD2K_1aluKR_tpevQ/certhash/uEiAfbgiymPP2_nX7Dgir8B4QkksjHp2lVuJZz0F79Be9JA') | ||
| ma.encapsulate('/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC') | ||
| ma.decapsulate('/quic-v1') | ||
|
|
||
| const ma2 = m(ma.bytes) | ||
| ma2.encapsulate('/tls/sni/example.com/http/http-path/path%2Findex.html') | ||
| ma2.equals(ma) | ||
|
|
||
| ma2.getPath() | ||
| ma2.getPeerId() | ||
|
|
||
| const ma3 = m('/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/udp/1234/quic-v1/webtransport/certhash/uEiAkH5a4DPGKUuOBjYw0CgwjvcJCJMD2K_1aluKR_tpevQ/certhash/uEiAfbgiymPP2_nX7Dgir8B4QkksjHp2lVuJZz0F79Be9JA') | ||
| ma3.encapsulate('/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC') | ||
| ma3.decapsulate('/quic-v1') | ||
| } |
There was a problem hiding this comment.
does this do any validation on the newer version? if not, it might be good to get a benchmark of the performance with the new validation to ensure there isn't a significant hit there..
Also, can we provide some recommendations for folks as to when & how to validate multiaddrs? i.e. only when reading multiaddr as a string, and then we don't need to again if using ma.* functions.. or whatever the case may be.
There was a problem hiding this comment.
Yes, the input is validated when the string is turned into a Multiaddr. If an operation is performed on two Multiaddrs internally, validation is skipped since the data was already validated.
Also, can we provide some recommendations for folks as to when & how to validate multiaddrs?
I backed off removing validation entirely. This should probably be done later as a breaking change since it may be disruptive.
Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
## [12.4.2](v12.4.1...v12.4.2) (2025-06-16) ### Bug Fixes * skip validation when encapsulating/decapsulating ([#420](#420)) ([c208caf](c208caf))
|
🎉 This PR is included in version 12.4.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Shifts expensive validation to
validatefunction which gives the user more control over operations take place.Skips validation when we create a multiaddr from an existing multiaddr.
Adds a
validatemethod that can perform explicit validation.For example we currently run multiple regex passes over IP addresses when creating new multiaddrs which can cause CPU bottlenecks.
Running the benchmark added in this PR it's an order of magnitude faster: