GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — plumbing: pktline, use Scanner for decoding by aymanbagabas · Pull Request #2038 · go-git/go-git Conversation
|
| 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%).
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.
There was an error while loading. Please reload this page.
adee60b to
6d43b20
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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:
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).pktline.Scanner documentation about buffer ownership and special pkt-lines.Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
| 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| 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 |
There was an error while loading. Please reload this page.
| wanted := len(b) | ||
|
|
||
| if size > wanted { | ||
| d.pending = read[wanted:] | ||
| d.pending = bytes.Clone(read[wanted:]) | ||
| } |
931d83f to
69d3501
Compare
There was a problem 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.
There was an error while loading. Please reload this page.
69d3501 to
e7620ae
Compare
Ahh, I think I lost the benchmark code I used here. But you can use any existing benchmarks that use clone and push 🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
e7620ae to
fc6f1f6
Compare
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]>
166e56a to
e21b024
Compare
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.