Skip to content

feat: add validate function and improve performance #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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

achingbrain
Copy link
Member

@achingbrain achingbrain commented Jun 5, 2025

Shifts expensive validation to validate function which gives the user more control over operations take place.

Basic validation is still performed (port numbers, IP syntax, etc) but it's no longer done every time we create a new multiaddr from existing data.

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:

┌─────────┬──────────────────────────────────┬─────────────┬────────┬───────┬────────┐
│ (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' │
└─────────┴──────────────────────────────────┴─────────────┴────────┴───────┴────────┘

@achingbrain achingbrain force-pushed the feat/add-validation-function branch 3 times, most recently from 6977a41 to df20b6b Compare June 5, 2025 15:16
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.
@achingbrain achingbrain force-pushed the feat/add-validation-function branch from df20b6b to ec0635f Compare June 5, 2025 15:25
@achingbrain achingbrain changed the title feat: add validate function feat: add validate function and improve performance Jun 6, 2025
@achingbrain
Copy link
Member Author

Refs: ipshipyard/roadmaps#1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant