Skip to content

pkg/reference: reduce allocations and improve GoDoc#10393

Merged
mxpv merged 4 commits intocontainerd:mainfrom
thaJeztah:improve_reference
Jun 27, 2024
Merged

pkg/reference: reduce allocations and improve GoDoc#10393
mxpv merged 4 commits intocontainerd:mainfrom
thaJeztah:improve_reference

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

pkg/reference: Spec.String(): use string-concatenation instead of sprintf

These were straight concatenations of strings; reduce some allocations by
removing fmt.Sprintf for this.

pkg/reference: SplitObject: zero allocations

Before / After:

BenchmarkSplitObject-10        2785656    428.1 ns/op     416 B/op    13 allocs/op
BenchmarkSplitObjectNew-10    13510520     88.2 ns/op       0 B/op     0 allocs/op

pkg/reference: SplitObject: add proper GoDoc

The behavior of this function is quite counter-intuitive, as it preserves
the delimiter in the result. This function should probably have been an
internal function, as its use for external consumers would be very limited,
but let's at least document the (surprising) behavior for those that are
considering to use it.

It appears that BuildKit is currently the only (publicly visible) external
consumer of this function; I am planning to inline its functionality in
Spec.Digest() and to deprecate this function so that it can be removed.

pkg/reference: Spec.Digest(): inline SplitObject code

Inline the relevant code from SplitObject, as we're only interested in
the digest portion.

…intf

These were straight concatenations of strings; reduce some allocations by
removing fmt.Sprintf for this.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Before / After:

    BenchmarkSplitObject-10        2785656    428.1 ns/op     416 B/op    13 allocs/op
    BenchmarkSplitObjectNew-10    13510520     88.2 ns/op       0 B/op     0 allocs/op

Signed-off-by: Sebastiaan van Stijn <[email protected]>
The behavior of this function is quite counter-intuitive, as it preserves
the delimiter in the result. This function should probably have been an
internal function, as its use for external consumers would be very limited,
but let's at least document the (surprising) behavior for those that are
considering to use it.

It appears that BuildKit is currently the only (publicly visible) external
consumer of this function; I am planning to inline its functionality in
Spec.Digest() and to deprecate this function so that it can be removed.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Inline the relevant code from SplitObject, as we're only interested
in the digest portion.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@mxpv mxpv added this pull request to the merge queue Jun 27, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 27, 2024
@thaJeztah
Copy link
Copy Markdown
Member Author

Hm... looks like the merge queue ran into a whoopsie on GitHub;

    log_hook.go:47: time="2024-06-27T16:57:41.716472960Z" level=info msg="trying next host" func="docker.(*dockerResolver).Resolve" file="/home/runner/actions-runner/_work/containerd/containerd/core/remotes/docker/resolver.go:311" error="failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://ghcr.io/token?scope=repository%3Acontainerd%2Fvolume-copy-up%3Apull&service=ghcr.io: 502 Bad Gateway" host=ghcr.io testcase=TestExportAndImportMultiLayer
    import_test.go:84: failed to resolve reference "ghcr.io/containerd/volume-copy-up:2.2": failed to authorize: failed to fetch anonymous token: unexpected status from GET request to https://ghcr.io/token?scope=repository%3Acontainerd%2Fvolume-copy-up%3Apull&service=ghcr.io: 502 Bad Gateway

@mxpv mxpv added this pull request to the merge queue Jun 27, 2024
Merged via the queue into containerd:main with commit ae7d74b Jun 27, 2024
@thaJeztah thaJeztah deleted the improve_reference branch June 27, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants