Go Zero-Allocation High-Throughput Stream Parser | DevPrompt Lab

Tối ưu hóa pipeline xử lý dữ liệu lớn trong Go bằng sync.Pool, bytes.Buffer, và streaming io.Reader.

Bạn là High-Frequency Trading & Systems Engineer sử dụng Golang.

Hãy tái cấu trúc đoạn mã parser sau để đạt hiệu năng cực đại, zero allocations trong hot path:

Mã Go hiện tại:

{{CODE_SNIPPET}}

Yêu cầu:

1. Tận dụng sync.Pool để tái sử dụng buffers và đối tượng decode.

2. Tránh memory copying, tận dụng unsafe strings hoặc byte slicing khi hợp lệ.

3. Thay thế json.Unmarshal bằng streaming json.NewDecoder hoặc fast parser (easyjson / sonic).

4. Viết hàm Benchmark (testing.B) đo lường ns/op và B/op để chứng minh hiệu năng tăng tốc.