-
Notifications
You must be signed in to change notification settings - Fork 67
fix: skip validation when encapsulating/decapsulating #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
achingbrain
wants to merge
14
commits into
main
Choose a base branch
from
feat/add-validation-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,546
−1,175
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ec0635f
feat: add validate function
achingbrain 0d0e6c4
chore: update tests
achingbrain 8fcd84c
chore: handle ///
achingbrain 6071326
chore: add benchmark
achingbrain 005db90
chore: no mutate
achingbrain 82c9fcc
chore: fix arr
achingbrain b1d01d4
chore: skip regex
achingbrain 5f08c78
chore: add more tests
achingbrain 6b32ad8
chore: update to latest spec
achingbrain d9ba88e
chore: deps
achingbrain d22df84
chore: linting
achingbrain deb7a29
chore: validate on create
achingbrain 1d8ce48
chore: use URL to normalise ipv6 addresses
achingbrain abe26e4
chore: linting
achingbrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# multiaddr Benchmark | ||
|
||
Benchmarks multiaddr performance during common operations - parsing strings, | ||
encapsulating/decapsulating addresses, turning to bytes, decoding bytes, etc. | ||
|
||
## Running the benchmarks | ||
|
||
```console | ||
% npm start | ||
|
||
> [email protected] start | ||
> npm run build && node dist/src/index.js | ||
|
||
|
||
> [email protected] build | ||
> aegir build --bundle false | ||
|
||
[06:10:56] tsc [started] | ||
[06:10:56] tsc [completed] | ||
┌─────────┬──────────────────────────────────┬─────────────┬────────┬───────┬────────┐ | ||
│ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ | ||
├─────────┼──────────────────────────────────┼─────────────┼────────┼───────┼────────┤ | ||
│ 0 │ 'head' │ '105679.89' │ '0.01' │ 50000 │ '0.01' │ | ||
│ 1 │ '@multiformats/[email protected]' │ '18244.31' │ '0.06' │ 50000 │ '0.13' │ | ||
└─────────┴──────────────────────────────────┴─────────────┴────────┴───────┴────────┘ | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "benchmarks-operations", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"clean": "aegir clean", | ||
"build": "aegir build --bundle false", | ||
"lint": "aegir lint", | ||
"dep-check": "aegir dep-check", | ||
"doc-check": "aegir doc-check", | ||
"start": "npm run build && node dist/test/index.js" | ||
}, | ||
"devDependencies": { | ||
"@multiformats/multiaddr-12.4.0": "npm:@multiformats/[email protected]", | ||
"@multiformats/multiaddr": "../../", | ||
"aegir": "^47.0.7", | ||
"tinybench": "^4.0.1" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { multiaddr } from '@multiformats/multiaddr' | ||
import { multiaddr as multiaddr12 } from '@multiformats/multiaddr-12.4.0' | ||
import { Bench } from 'tinybench' | ||
|
||
const ITERATIONS = parseInt(process.env.ITERATIONS ?? '50000') | ||
const MIN_TIME = parseInt(process.env.MIN_TIME ?? '1') | ||
const RESULT_PRECISION = 2 | ||
|
||
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') | ||
} | ||
|
||
async function main (): Promise<void> { | ||
const suite = new Bench({ | ||
iterations: ITERATIONS, | ||
time: MIN_TIME | ||
}) | ||
suite.add('head', () => { | ||
bench(multiaddr) | ||
}) | ||
suite.add('@multiformats/[email protected]', () => { | ||
bench(multiaddr12) | ||
}) | ||
|
||
await suite.run() | ||
|
||
console.table(suite.tasks.map(({ name, result }) => { | ||
if (result?.error != null) { | ||
console.error(result.error) | ||
|
||
return { | ||
Implementation: name, | ||
'ops/s': 'error', | ||
'ms/op': 'error', | ||
runs: 'error', | ||
p99: 'error' | ||
} | ||
} | ||
|
||
return { | ||
Implementation: name, | ||
'ops/s': result?.hz.toFixed(RESULT_PRECISION), | ||
'ms/op': result?.period.toFixed(RESULT_PRECISION), | ||
runs: result?.samples.length, | ||
p99: result?.p99.toFixed(RESULT_PRECISION) | ||
} | ||
})) | ||
} | ||
|
||
main().catch(err => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"extends": "aegir/src/config/tsconfig.aegir.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": [ | ||
"src", | ||
"test" | ||
], | ||
"references": [ | ||
{ | ||
"path": "../../" | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.