Skip to content

Reuse raw event structs with sync.Pool#4

Merged
fanyang89 merged 1 commit intomainfrom
3ax123-codex/add-object-pool-for-event-struct
Feb 9, 2026
Merged

Reuse raw event structs with sync.Pool#4
fanyang89 merged 1 commit intomainfrom
3ax123-codex/add-object-pool-for-event-struct

Conversation

@fanyang89
Copy link
Collaborator

Motivation

  • Reduce per-event allocations when parsing bpftrace NDJSON/logfmt output by reusing event structs.
  • Improve performance and GC pressure for high-throughput printf event streams.

Description

  • Add a sync.Pool for raw event types and import sync in cmd_net.go, cmd_proc.go, cmd_mem.go, cmd_syscall.go, and cmd_vfs_raw.go.
  • Reset pooled instances before parsing with *e = <Type>{} and unmarshal into the pooled object (e.g. logfmt.Unmarshal(buf, e)).
  • Return pooled objects to the pool on both success and failure paths to avoid leaks, and call appendRow with the pooled pointer (e.g. err = appendRow(e)).
  • Updated parsing functions: netJSONParseThenAppend, procJSONParseThenAppend, memJSONParseThenAppend, syscallJSONParseThenAppend, and both parse paths in cmd_vfs_raw.go to use the pools.

Testing

  • Files were formatted with gofmt -w to ensure idiomatic formatting.
  • No automated unit tests were executed as part of this change.

Codex Task

@fanyang89 fanyang89 merged commit 5700a37 into main Feb 9, 2026
2 checks passed
@fanyang89 fanyang89 deleted the 3ax123-codex/add-object-pool-for-event-struct branch February 9, 2026 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant