From 91bbccf95b8de5942c619338b6c7d7e73bb33fb3 Mon Sep 17 00:00:00 2001 From: Evgeniy Belyi Date: Thu, 13 Jul 2023 00:21:01 +0300 Subject: [PATCH] Improve StreamBuf append (#35928) * Improve streambuf append * Adding changelog comment * Update CHANGELOG.next.asciidoc Co-authored-by: Craig MacKenzie --------- Co-authored-by: Craig MacKenzie --- CHANGELOG.next.asciidoc | 3 +-- libbeat/common/streambuf/streambuf.go | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 3f999f67782..25a6b617a63 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -71,9 +71,8 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Upgraded apache arrow library used in x-pack/libbeat/reader/parquet from v11 to v12.0.1 in order to fix cross-compilation issues {pull}35640[35640] - Fix panic when MaxRetryInterval is specified, but RetryInterval is not {pull}35820[35820] - Do not print context cancelled error message when running under agent {pull}36006[36006] - - - Fix recovering from invalid output configuration when running under Elastic-Agent {pull}36016[36016] +- Improve StreamBuf append to improve performance when reading long lines from files. {pull}35928[35928] *Auditbeat* diff --git a/libbeat/common/streambuf/streambuf.go b/libbeat/common/streambuf/streambuf.go index f28c2157792..48bbabae0d5 100644 --- a/libbeat/common/streambuf/streambuf.go +++ b/libbeat/common/streambuf/streambuf.go @@ -155,7 +155,9 @@ func (b *Buffer) doAppend(data []byte, retainable bool, newCap int) error { b.data = tmp } } - b.data = append(b.data, data...) + tBuf := bytes.NewBuffer(b.data) + tBuf.Write(data) + b.data = tBuf.Bytes() } b.available += len(data)