miller/pkg/output
John Kerl d2acbfeea3 Batch-allocate per-record objects; reuse CSV writer field buffer
After batch-arena field allocation, profiling cat over 1M-record CSV showed
the remaining ~5M allocations were almost entirely per-record (one each):
the Mlrmap struct, the RecordAndContext wrapper, the CSV writer's []string,
and the go-csv parser's own buffers.

Address the first three:

- mlrval.RecordArena gains NewRecord(), vending the Mlrmap struct itself from
  a per-batch slab (respecting --no-hash-records). Rolled out to every
  line-based reader (CSV, CSV-lite, TSV, DKVP, NIDX, PPRINT, XTAB, DKVPX) in
  place of NewMlrmapAsRecord.

- The CSV reader batch-allocates RecordAndContext wrappers from a per-batch
  slab instead of one heap object per record (comment/output-string entries
  still allocate individually, but they are rare).

- RecordWriterCSV reuses a single fieldsBuffer []string across records instead
  of allocating one per Write; WriteCSVRecordMaybeColorized consumes it
  synchronously and the writer is single-goroutine, so this is safe.

Effect (big.*, 1M records, cat, best of 5):
  csv   0.26 -> 0.22
  dkvp  0.51 -> 0.45  (Mlrmap slab)

For CSV, cat's allocation-object count drops ~5.0M -> ~2.1M. The remaining
~2M are the go-csv parser's per-record backing string and field slice, which
are intrinsic to parsing and would require a zero-copy/batch-slab parser
rework. A CPU profile of cat now shows it is I/O-bound (syscall ~56%, bufio
read+flush), with allocation/GC down to ~10% -- i.e. further allocation
trimming no longer moves cat's wall-clock. GOGC=off confirms (no change).

Verified: go test ./pkg/... and full regression suite pass; output is
byte-identical across all formats including record-retaining verbs (tac),
hashed and --no-hash-records.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-19 12:27:22 -04:00
..
channel_writer.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
doc.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
file_output_handlers.go Some fixes for staticcheck (#2006) 2026-03-03 09:27:03 -05:00
README.md Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
record_writer.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
record_writer_csv.go Batch-allocate per-record objects; reuse CSV writer field buffer 2026-06-19 12:27:22 -04:00
record_writer_csv_colorizer.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
record_writer_csvlite.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
record_writer_dcf.go Some fixes for staticcheck (#2006) 2026-03-03 09:27:03 -05:00
record_writer_dkvp.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
record_writer_dkvpx.go Add DKVPX file format (#2002) 2026-03-02 22:35:08 -05:00
record_writer_factory.go Add DKVPX file format (#2002) 2026-03-02 22:35:08 -05:00
record_writer_json_jsonl.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
record_writer_markdown.go Fix column alignment for wide and combining Unicode chars (#1520, #379) (#2061) 2026-05-17 12:12:54 -04:00
record_writer_nidx.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
record_writer_pprint.go Fix PPRINT alignment with multi-character OFS (#1819) (#2063) 2026-05-17 12:45:49 -04:00
record_writer_tsv.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
record_writer_xtab.go Fix column alignment for wide and combining Unicode chars (#1520, #379) (#2061) 2026-05-17 12:12:54 -04:00
record_writer_yaml.go fix: preserve key order in YAML output (#2034) 2026-04-12 09:43:09 -04:00

Logic for formatting output records as strings to standard output.

There is one record-writer type per supported output file format, and a factory method.