Skip to content

Commit 10c6809

Browse files
committed
Micro-optimization: just use a new buffer
GCing old buffers and allocating new ones is very fast, reseting the buffer requires rewriting the backing array in a way that's slow enough to show up on a flamegraph.
1 parent 6f10616 commit 10c6809

File tree

1 file changed

+2
-2
lines changed
  • modules/ingest-common/src/main/java/org/elasticsearch/ingest/common

1 file changed

+2
-2
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CefParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ CefEvent process(String cefString) {
313313
static List<String> parseHeaders(String cefString) {
314314
List<String> headers = new ArrayList<>();
315315
int extensionStart = -1;
316-
final StringBuilder buffer = new StringBuilder();
316+
StringBuilder buffer = new StringBuilder();
317317
for (int i = 0; i < cefString.length(); i++) {
318318
char curr = cefString.charAt(i);
319319
char next = i < cefString.length() - 1 ? cefString.charAt(i + 1) : '\0';
@@ -325,7 +325,7 @@ static List<String> parseHeaders(String cefString) {
325325
i++; // and skip the next character
326326
} else if (curr == '|') { // a pipe, it's the end of a header
327327
headers.add(buffer.toString()); // emit the header
328-
buffer.setLength(0); // and reset the buffer
328+
buffer = new StringBuilder(); // and reset the buffer
329329
if (headers.size() == 7) {
330330
extensionStart = i + 1; // the extensions begin after this pipe
331331
break; // we've processed all the headers, so exit the loop

0 commit comments

Comments
 (0)