GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — plumbing: pktline, use Scanner for decoding by aymanbagabas · Pull Request #2038 · go-git/go-git

Conversation

@aymanbagabas

@aymanbagabas aymanbagabas commented Apr 25, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This uses the existing pktline.Scanner for decoding pkt-line based
messages in the packp protocol, replacing the previous use of
pktline.ReadLine. This allows for more efficient decoding by avoiding
unnecessary allocations and copying of data, while still providing a
convenient API for accessing the payload of pkt-lines.

This is based on #1987
The only change on top of the above PR is adee60b

Benchmarks before and after:

goos: darwin
goarch: arm64
pkg: github.com/go-git/go-git/v6/plumbing/protocol/packp/sideband
cpu: Apple M3 Max
                       │ /tmp/bench_sideband_parent.txt │   /tmp/bench_sideband_current2.txt    │
                       │             sec/op             │    sec/op      vs base                │
Demuxer/small_100-16                       6.190µ ± ∞ ¹    7.743µ ± ∞ ¹   +25.09% (p=0.008 n=5)
Demuxer/small_1000-16                      61.11µ ± ∞ ¹    37.00µ ± ∞ ¹   -39.45% (p=0.008 n=5)
Demuxer/medium_100-16                      61.44µ ± ∞ ¹    18.42µ ± ∞ ¹   -70.02% (p=0.008 n=5)
Demuxer/medium_1000-16                     430.4µ ± ∞ ¹    145.4µ ± ∞ ¹   -66.21% (p=0.008 n=5)
Demuxer/large_100-16                       533.6n ± ∞ ¹   4497.0n ± ∞ ¹  +742.77% (p=0.008 n=5)
Demuxer/large_1000-16                      4.758µ ± ∞ ¹    7.155µ ± ∞ ¹   +50.38% (p=0.008 n=5)
geomean                                    17.14µ          17.06µ          -0.46%
¹ need >= 6 samples for confidence interval at level 0.95

                       │ /tmp/bench_sideband_parent.txt │    /tmp/bench_sideband_current2.txt    │
                       │              B/s               │      B/s        vs base                │
Demuxer/small_100-16                     1097.5Mi ± ∞ ¹    877.4Mi ± ∞ ¹   -20.05% (p=0.008 n=5)
Demuxer/small_1000-16                     1.085Gi ± ∞ ¹    1.792Gi ± ∞ ¹   +65.15% (p=0.008 n=5)
Demuxer/medium_100-16                     6.220Gi ± ∞ ¹   20.744Gi ± ∞ ¹  +233.52% (p=0.008 n=5)
Demuxer/medium_1000-16                    8.879Gi ± ∞ ¹   26.279Gi ± ∞ ¹  +195.98% (p=0.008 n=5)
Demuxer/large_100-16                     400.34Mi ± ∞ ¹    47.50Mi ± ∞ ¹   -88.13% (p=0.008 n=5)
Demuxer/large_1000-16                     441.7Mi ± ∞ ¹    293.8Mi ± ∞ ¹   -33.50% (p=0.008 n=5)
geomean                                   1.488Gi          1.494Gi          +0.47%
¹ need >= 6 samples for confidence interval at level 0.95

                       │ /tmp/bench_sideband_parent.txt │     /tmp/bench_sideband_current2.txt     │
                       │              B/op              │      B/op       vs base                  │
Demuxer/small_100-16                      8.123Ki ± ∞ ¹   72.047Ki ± ∞ ¹    +786.94% (p=0.008 n=5)
Demuxer/small_1000-16                     80.75Ki ± ∞ ¹    72.05Ki ± ∞ ¹     -10.78% (p=0.008 n=5)
Demuxer/medium_100-16                    479.73Ki ± ∞ ¹    72.05Ki ± ∞ ¹     -84.98% (p=0.008 n=5)
Demuxer/medium_1000-16                  4770.56Ki ± ∞ ¹    72.05Ki ± ∞ ¹     -98.49% (p=0.008 n=5)
Demuxer/large_100-16                        289.0 ± ∞ ¹    73776.0 ± ∞ ¹  +25428.03% (p=0.008 n=5)
Demuxer/large_1000-16                     2.399Ki ± ∞ ¹   72.047Ki ± ∞ ¹   +2902.69% (p=0.008 n=5)
geomean                                   31.71Ki          72.05Ki          +127.21%
¹ need >= 6 samples for confidence interval at level 0.95

                       │ /tmp/bench_sideband_parent.txt │  /tmp/bench_sideband_current2.txt  │
                       │           allocs/op            │  allocs/op   vs base               │
Demuxer/small_100-16                      111.000 ± ∞ ¹   2.000 ± ∞ ¹  -98.20% (p=0.008 n=5)
Demuxer/small_1000-16                    1101.000 ± ∞ ¹   2.000 ± ∞ ¹  -99.82% (p=0.008 n=5)
Demuxer/medium_100-16                     111.000 ± ∞ ¹   2.000 ± ∞ ¹  -98.20% (p=0.008 n=5)
Demuxer/medium_1000-16                   1103.000 ± ∞ ¹   2.000 ± ∞ ¹  -99.82% (p=0.008 n=5)
Demuxer/large_100-16                       11.000 ± ∞ ¹   2.000 ± ∞ ¹  -81.82% (p=0.008 n=5)
Demuxer/large_1000-16                     101.000 ± ∞ ¹   2.000 ± ∞ ¹  -98.02% (p=0.008 n=5)
geomean                                     159.8         2.000        -98.75%
¹ need >= 6 samples for confidence interval at level 0.95

Pktline: Scanner vs ReadLine

Metric Scanner ReadLine Δ
Allocs/line 0 1 -100%
sec/op (sections) 252.7n 412.9n (ReadLine) -39% faster

Scanner is zero-alloc; ReadLine allocates 1 heap object per line. Latency differences within the ReadPacket baseline are noise (~1-3%).

Sideband Demuxer (hot path)

Allocations (the primary win):

Scenario Parent (ReadLine) Current (Scanner) Δ
small_100 111 2 -98%
small_1000 1101 2 -99.8%
medium_100 111 2 -98%
medium_1000 1103 2 -99.8%
large_1000 101 2 -98%

Throughput (realistic medium payloads):

Scenario Parent Current Δ
medium_100 6.1 GB/s 20.6 GB/s +239%
medium_1000 8.5 GB/s 26.0 GB/s +206%

Trade-off: The Scanner's 65KB heap-allocated buffer costs ~72KB vs ~8KB for small payloads with ReadLine's pool. For small payloads (64B) the larger buffer overhead makes latency worse (+22%). For realistic 4KB+ payloads this is massively outweighed by the eliminated allocations.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aymanbagabas
aymanbagabas requested a review from pjbgf April 25, 2026 21:53
@aymanbagabas aymanbagabas changed the title lumbing: pktline, use Scanner for decoding plumbing: pktline, use Scanner for decoding Apr 25, 2026
@aymanbagabas
aymanbagabas force-pushed the pktline-scanner branch 3 times, most recently from adee60b to 6d43b20 Compare May 4, 2026 14:56
@aymanbagabas
aymanbagabas marked this pull request as ready for review May 4, 2026 14:57
Copilot AI review requested due to automatic review settings May 4, 2026 14:57
Copilot started reviewing on behalf of aymanbagabas May 4, 2026 14:57
View session
Copilot AI reviewed May 4, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Pull request overview

This PR migrates multiple pkt-line–based decoders in plumbing/protocol/packp (and related transport code) from pktline.ReadLine to the existing pktline.Scanner, aiming to reduce allocations/copies while keeping the decoding APIs straightforward.

Changes:

  • Replace pktline.ReadLine loops with pktline.Scanner across packp decoders (advrefs, upload-request/haves, update-requests, server responses, shallow updates, push options, git proto request, smart HTTP reply).
  • Update sideband demuxing to reuse a scanner instance and adjust buffering behavior.
  • Clarify pktline.Scanner documentation about buffer ownership and special pkt-lines.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
plumbing/transport/upload_archive.go Use pktline.Scanner to read upload-archive argument pkt-lines.
plumbing/transport/archive.go Use pktline.Scanner to read ACK/NACK + flush before sideband stream.
plumbing/protocol/packp/uphav.go Decode upload-pack haves using pktline.Scanner.
plumbing/protocol/packp/updreq_decode.go Decode update-requests using a shared pktline.Scanner.
plumbing/protocol/packp/ulreq_decode.go Decode upload-request using pktline.Scanner and clone data for error reporting.
plumbing/protocol/packp/srvresp.go Decode server ACK/NAK response using pktline.Scanner.
plumbing/protocol/packp/smart.go Decode smart HTTP service header + flush using pktline.Scanner.
plumbing/protocol/packp/sideband/demux.go Demux sideband packets using an internal pktline.Scanner and adjust pending buffering.
plumbing/protocol/packp/shallowupd.go Decode shallow/unshallow updates with pktline.Scanner.
plumbing/protocol/packp/report_status.go Decode report-status with pktline.Scanner and updated first-line scanning.
plumbing/protocol/packp/pushopts.go Decode push-options using pktline.Scanner.
plumbing/protocol/packp/gitproto.go Decode git protocol request using pktline.Scanner.
plumbing/protocol/packp/advrefs_decode.go Decode advertised-refs using pktline.Scanner and clone data for error reporting.
plumbing/format/pktline/scanner.go Update scanner documentation around buffer lifetime and special pkt-lines.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread plumbing/protocol/packp/report_status.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plumbing/transport/upload_archive.go
Comment on lines +149 to 167
sc := pktline.NewScanner(r)
for sc.Scan() {
if sc.Len() == pktline.Flush {
break
}
if len(args) >= maxArchiveArgs {
return nil, fmt.Errorf("upload-archive: too many arguments (>%d)", maxArchiveArgs)
}

s := strings.TrimSuffix(string(line), "\n")
if !strings.HasPrefix(s, "argument ") {
return nil, fmt.Errorf("upload-archive: expected 'argument' token, got: %s", s)
line := strings.TrimSuffix(sc.Text(), "\n")
if !strings.HasPrefix(line, "argument ") {
return nil, fmt.Errorf("upload-archive: expected 'argument' token, got: %s", line)
}
args = append(args, s[len("argument "):])
args = append(args, line[len("argument "):])
}
if err := sc.Err(); err != nil {
return nil, fmt.Errorf("upload-archive: reading argument: %w", err)
}
return args, nil
Comment thread plumbing/protocol/packp/pushopts.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread plumbing/protocol/packp/sideband/demux.go
Comment on lines 87 to 91
wanted := len(b)

if size > wanted {
d.pending = read[wanted:]
d.pending = bytes.Clone(read[wanted:])
}
@aymanbagabas
aymanbagabas force-pushed the pktline-scanner branch 3 times, most recently from 931d83f to 69d3501 Compare May 6, 2026 15:26
pjbgf
pjbgf reviewed May 13, 2026
View reviewed changes

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

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.

@aymanbagabas LGTM - apart from the outliers on the benchstat.
Did you manage to find the reason for it?

Demuxer/large_100-16                       533.6n ± ∞ ¹   4497.0n ± ∞ ¹  +742.77% (p=0.008 n=5)
Demuxer/large_1000-16                      4.758µ ± ∞ ¹    7.155µ ± ∞ ¹   +50.38% (p=0.008 n=5)


Demuxer/medium_100-16                     6.220Gi ± ∞ ¹   20.744Gi ± ∞ ¹  +233.52% (p=0.008 n=5)
Demuxer/medium_1000-16                    8.879Gi ± ∞ ¹   26.279Gi ± ∞ ¹  +195.98% (p=0.008 n=5)


Demuxer/large_100-16                        289.0 ± ∞ ¹    73776.0 ± ∞ ¹  +25428.03% (p=0.008 n=5)
Demuxer/large_1000-16                     2.399Ki ± ∞ ¹   72.047Ki ± ∞ ¹   +2902.69% (p=0.008 n=5)

Please rebase and share the benchmark code used so that I can cross-check that in Linux. Some of it could be added to the PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@aymanbagabas
aymanbagabas force-pushed the pktline-scanner branch from 69d3501 to e7620ae Compare May 14, 2026 01:48
@aymanbagabas

aymanbagabas commented May 14, 2026

Copy link
Copy Markdown
Member Author

Please rebase and share the benchmark code used so that I can cross-check that in Linux. Some of it could be added to the PR.

Ahh, I think I lost the benchmark code I used here. But you can use any existing benchmarks that use clone and push 🙂

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aymanbagabas
aymanbagabas requested a review from pjbgf May 16, 2026 02:25
@aymanbagabas
aymanbagabas force-pushed the pktline-scanner branch from e7620ae to fc6f1f6 Compare May 16, 2026 02:38
@aymanbagabas aymanbagabas mentioned this pull request May 16, 2026
plumbing: format/pktline, fold sideband into pktline and drop the sideband package #2130
Open
@aymanbagabas
plumbing: pktline, use Scanner for decoding
e21b024
This uses the existing pktline.Scanner for decoding pkt-line based
messages in the packp protocol, replacing the previous use of
pktline.ReadLine. This allows for more efficient decoding by avoiding
unnecessary allocations and copying of data, while still providing a
convenient API for accessing the payload of pkt-lines.

Signed-off-by: Ayman Bagabas <[email protected]>
@aymanbagabas
aymanbagabas force-pushed the pktline-scanner branch from 166e56a to e21b024 Compare June 24, 2026 13:45
pjbgf
pjbgf approved these changes Jun 24, 2026
View reviewed changes

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

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.

@aymanbagabas thanks for working on this. 🙇

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@pjbgf
pjbgf merged commit bf2347e into go-git:main Jun 24, 2026
17 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@pjbgf pjbgf pjbgf approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@aymanbagabas @pjbgf
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.