Skip to content

Conversation

@andrew
Copy link

@andrew andrew commented Jan 25, 2026

Replace regex validators with hand-written character checks, use strings.Builder for ToString, implement custom purl parser, and avoid reflection-based sorting. Also fixes query string escaping for qualifiers and subpaths per purl spec.

Spec submodule updated and all tests passing.

Benchmarks on Apple M1 Pro:

Parsing (FromString)

Benchmark Before After Speedup Memory
Simple 335 ns 155 ns 2.2x 184B → 40B
Namespace 412 ns 191 ns 2.2x 184B → 40B
Complex 1811 ns 551 ns 3.3x 584B → 360B

Serialization (ToString)

Benchmark Before After Speedup Memory
Simple 192 ns 61 ns 3.2x 136B/5 allocs → 64B/1 alloc
Namespace 291 ns 118 ns 2.5x 248B/6 allocs → 96B/1 alloc
Complex 897 ns 273 ns 3.3x 776B/21 allocs → 336B/3 allocs

Validation (regex → hand-written)

Benchmark Before After Speedup
ValidQualifierKey 669 ns 32 ns 21x
ValidType 559 ns 22 ns 25x

Roundtrip (Parse + Serialize)

Benchmark Before After Speedup Memory
Simple 550 ns 233 ns 2.4x 320B → 104B
Complex 2978 ns 858 ns 3.5x 1360B → 696B

Replace regex validators with hand-written character checks, use strings.Builder for ToString, implement custom purl parser, and avoid reflection-based sorting. Add benchmarks. Fix query string escaping for qualifiers and subpaths per purl spec.
@petergardfjall
Copy link
Collaborator

petergardfjall commented Feb 10, 2026

Thanks for the PR! There is a rather big PR in the pipeline (#83) that attempts to adapt the code to pass all the new tests in the upstream purl-spec. It is awaiting a second round of approval. I'd prefer having that merged first before applying optimizations.

@andrew
Copy link
Author

andrew commented Feb 10, 2026

I have also fixed almost all of the tests in this branch

Stop stripping trailing slashes and default registry from bazel
repository_url qualifiers. Add otp and vscode-extension type
validation: otp prohibits namespace, vscode-extension requires it.
@andrew
Copy link
Author

andrew commented Feb 10, 2026

@petergardfjall I've updated the spec submodule and got all tests passing, so this should be good to go. I'm now shipping it in https://github.com/git-pkgs/git-pkgs because the current version has some real slow bits when parsing thousands of purls.

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.

2 participants