miller/pkg/mlrval
John Kerl d00de0f71a
Batch-allocate per-record objects; reuse CSV writer field buffer (#2083)
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 17:03:04 -04:00
..
mlrmap.go Lazy per-record hashing: ~15-30% faster on common workloads (#2081) 2026-06-19 16:37:42 -04:00
mlrmap_accessors.go Batch-arena field allocation for line-based readers (#2082) 2026-06-19 16:40:05 -04:00
mlrmap_accessors_test.go Implement mlr uniq -x (#1457) 2023-12-23 16:20:11 -05:00
mlrmap_flatten_unflatten.go Fix issue #1983 (#2040) 2026-04-19 10:44:53 -04:00
mlrmap_json.go Performance and style fixes (#1981) 2026-02-18 09:19:31 -05:00
mlrmap_new_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrmap_print.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_accessors.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_benchmark_test.go The package version must match the major tag version (#1654) 2024-09-20 12:10:11 -04:00
mlrval_cmp.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_cmp_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_collections.go Allow empty-string keys in JSON and YAML input (#2068) 2026-05-27 20:19:03 -04:00
mlrval_constants.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_copy.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_format.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_format_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_get.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_get_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_infer.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_infer_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_is.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_is_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_json.go Allow empty-string keys in JSON and YAML input (#2068) 2026-05-27 20:19:03 -04:00
mlrval_new.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_new_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_output.go Performance and style fixes (#1981) 2026-02-18 09:19:31 -05:00
mlrval_output_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_sort.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_sort_test.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_type.go Multiple style updates (#1974) 2026-02-16 15:49:21 -05:00
mlrval_type_test.go Export library code in pkg/ (#1391) 2023-09-10 17:15:13 -04:00
mlrval_yaml.go Allow empty-string keys in JSON and YAML input (#2068) 2026-05-27 20:19:03 -04:00
mlrval_yaml_test.go fix: preserve key order in YAML output (#2034) 2026-04-12 09:43:09 -04:00
record_arena.go Batch-allocate per-record objects; reuse CSV writer field buffer (#2083) 2026-06-19 17:03:04 -04:00