From d6d18a2d618adffa833e0d7d7ef1c1069093fbee Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sun, 6 Jul 2025 23:39:50 +0200 Subject: [PATCH] perf(reader): shrink the json detection buffer There is no need to allocate half a kilobyte of memory only check that a buffer starts with a bunch of spaces and a `{`, 32b should be more than enough. Also, no need to allocate it on the heap, having it on the stack works perfectly. --- internal/reader/parser/format.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/reader/parser/format.go b/internal/reader/parser/format.go index 7919ccf2..ceff4513 100644 --- a/internal/reader/parser/format.go +++ b/internal/reader/parser/format.go @@ -22,7 +22,8 @@ const ( // DetectFeedFormat tries to guess the feed format from input data. func DetectFeedFormat(r io.ReadSeeker) (string, string) { - data := make([]byte, 512) + var dataArray = [32]byte{} + data := dataArray[:] r.Read(data) if bytes.HasPrefix(bytes.TrimSpace(data), []byte("{")) {