Skip to content

perf(internal): pack from end without cloning input - #1953

Open
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:perf/pack-end-no-clone
Open

perf(internal): pack from end without cloning input#1953
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:perf/pack-end-no-clone

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

  • PackEnd now iterates over the input slice backwards instead of cloning and reversing it.
  • It reuses the packed outer slice instead of allocating a second [][]T.
  • The input slice remains unchanged.
  • Empty input keeps returning a non-nil empty result.

Benchmarks

Ran on an Apple M1 Pro with Go 1.26.3. Medians from five runs:

  • int64, 128 items: 1.27 us, 3,160 B/op, 12 allocs/op -> 0.96 us, 2,112 B/op, 10 allocs/op
  • 64-byte item, 16,384 items: 604 us, 3.16 MB/op, 1,162 allocs/op -> 461 us, 2.11 MB/op, 1,160 allocs/op
  • 64-byte item, 131,072 items: 4.41 ms, 25.27 MB/op, 9,229 allocs/op -> 4.04 ms, 16.85 MB/op, 9,227 allocs/op

Tests

  • go test -timeout=5m $(go list ./... | rg -v "/io/gocloud$")
  • go test -race -timeout=5m ./internal ./table/...
  • golangci-lint run --timeout=10m

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