Repository navigation
Reduced per-render allocations in table rendering - #26
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Table.String()now allocates about half as many objects and bytes per render while producing byte-identical output. No functionality is added for callers: the exported API and every rendered byte are unchanged, so this is a patch-level release (1.2.1).Changes
Table.String(),Table.line(),Table.borderLeftRight(),tblRow.toStringSlice(), andcontent.line()now build into one pre-grownstrings.Builderor plain concatenation: the per-linefmt.Sprintfcalls are gone, the cell separator" " + style.Cell + " "is hoisted out of the line loop, and padding spaces are written from a reusable constant instead ofstrings.Repeat.sync.Poolof the internal*contentobject cuts per-cell-per-render allocations: the object is fully reset on reuse, and the previous object is released when its cell's content is reassigned. This removes the per-renderstrings.Splitallocation for single-line cells.v1.2.0;Print/Printlnare untouched.golden_test.gopinsTable.String()byte for byte for all seven built-in styles plus multiline, ANSI-colored, CJK-wide, and spanned fixtures (testdata/*.golden), with-update-goldento regenerate.concurrency_test.goadds a repeated-render stability check and a-racedistinct-tables test.reduce-render-allocationsadds thetable-outputrequirement "Bound per-render allocations" with four scenarios; the change is archived in this diff and the synced spec is updated.1.2.1entry.Per-benchmark allocation measurements against the recorded
v1.2.0baseline:The gate is per benchmark, not aggregate.
ns/opis not gated: on the fixed test machine it carries ±20% noise, whileallocs/opreproduces exactly.Test plan
make check— test, build,golangci-lint(root module and_example/03-benchmarks-with-others),golangci-lint fmt --diff, andopenspec validate --all --strict(5 specs) — all green.make bench— the table above; every benchmark clears both ceilings.go test -race -run 'TestConcurrent|TestReRender|TestGolden' .— no data race, all golden and stability subtests pass.1c796cerenders byte-identical output to the committed fixtures, so the fixtures were frozen before any source edit rather than blessed afterwards.go doc -all .is byte-identical between1c796ceand this branch;Print/Printlnare unchanged.Not included
make bench-compare(Makefile:51) still points at the module root of_example/03-benchmarks-with-others, which has no test files, so it runs zero benchmarks. That defect is inherited frommasterand is intentionally left for a separate change; the numbers published here come from the equivalent harness invocation in_example/03-benchmarks-with-others/bench.