8000 Reduce ASC formatting and ISO-TP frame allocations by tomrford · Pull Request #84 · tomrford/gocan · GitHub
[go: up one dir, main page]

Skip to content

Reduce ASC formatting and ISO-TP fr 8000 ame allocations - #84

Merged
tomrford merged 4 commits into
mainfrom
perf/format-and-transmit-buffers
Sep 20, 2026
Merged

tomrford merged 4 commits into
mainfrom
perf/format-and-transmit-buffers

Conversation

@tomrford
Copy link
Copy Markdown
Owner

ASC writing formats every payload byte through fmt and allocates temporary record strings. Build the complete line, including its timestamp, in a reusable byte buffer; share classical data/remote formatting and preserve the emitted bytes. ISO-TP consecutive-frame construction and padding use local fixed-size arrays, retaining the existing padding logic. Extract the repeated newest-cursor lookup from Capture reads.

On Apple M4 with Go 1.26.6, three-run microbenchmarks measured:

Operation Main This branch Allocations before → after
ASC, 8-byte frame ~530 ns ~52 ns 9 → 0
ASC, 64-byte FD frame ~2,347 ns ~94 ns 12 → 0
ISO-TP full FD consecutive-frame construction ~29 ns ~22 ns 1 → 0

ASC benchmarks cover steady-state formatting to io.Discard. ISO-TP figures isolate frame construction. Capture read benchmarks remained close to main.

Validation:

  • go test -race ./..., go vet ./..., formatting and diff checks.
  • Windows amd64, arm64 and 386 compile tests.
  • Exact ASC timestamp tests covering fractional padding, second rollover and seconds wider than the minimum field width; existing mixed-record lifecycle checks include writes after Close.
  • Temporary differential comparison against the original ASC writer: 1,920 valid frame cases produced identical bytes.
  • python-can 4.6.1 independently verified classical, remote, FD and error frames, including payloads, flags, channels and timestamps. Proprietary Vector conformance tooling was not run.
  • Temporary ISO-TP wire checks covered configured lengths, requested/required padding, shortened final frames and sequence rollover.

Net change: 64 production lines and 75 test/benchmark lines.

tomrford and others added 4 commits September 20, 2026 22:26
WriteFrame built every record through fmt.Fprintf and strings.Builder,
paying reflection and boxing per field and once per payload byte. Build
the body into a reusable scratch with strconv appends and a hex table,
and emit the fixed timestamp prefix from the same helpers. Output is
byte-identical; the streams test pins every line.

Amp-Thread-ID: https://ampcode.com/threads/T-01a0bfe9-fc6d-752f-a896-035e03901034
Co-authored-by: Amp <amp@ampcode.com>
@tomrford
tomrford marked this pull request as ready for review September 20, 2026 20:33
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-20T20:37:33.155615Z 1f4ee8f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@tomrford
tomrford merged commit 4aa4c09 into main Sep 20, 2026
1 check passed
@tomrford
tomrford deleted the perf/format-and-transmit-buffers branch September 20, 2026 20:41
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

0