Skip to content

gen: optimize unconstrained byte array serialization - #3

Open
gabrix73 wants to merge 1 commit into
katzenpost:masterfrom
gabrix73:perf/byte-array-copy
Open

gen: optimize unconstrained byte array serialization#3
gabrix73 wants to merge 1 commit into
katzenpost:masterfrom
gabrix73:perf/byte-array-copy

Conversation

@gabrix73

Copy link
Copy Markdown

Summary

  • emit one bounds check and copy when parsing unconstrained u8 and char arrays
  • append byte slices directly when encoding and omit empty per-byte validation loops
  • retain element-by-element handling for constrained byte types
  • regenerate affected fixtures and add benchmarks plus an input-ownership regression test

The parser still copies decoded bytes into owned storage, so mutating the input buffer after parsing does not change the decoded value.

Benchmark

64 KiB leftover byte array on linux/amd64, Intel i5-6300U, median of three 500 ms runs:

Operation Before After Allocations
Parse 208016 ns/op 23563 ns/op 23 to 2
Marshal 171976 ns/op 23572 ns/op 22 to 2

Command:

go test ./gen/tests/rem -run '^$' -bench 'Benchmark(Parse|Marshal)ByteTail$' -benchmem -benchtime=500ms -count=3

Verification

  • go test ./...
  • go vet ./...
  • git diff --check

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