From 0eaa7707f1101a955450c0328826ba86e8fc307d Mon Sep 17 00:00:00 2001 From: Shaun Patterson Date: Thu, 28 May 2026 14:14:02 -0400 Subject: [PATCH] perf(chunker): lazy facets map + strconv.FormatUint in mapToNquads Allocate rawFacets only on the first facet key (most objects have none) and replace fmt.Sprintf("%d", uid) with strconv.FormatUint. BenchmarkParseJSON (9 nested objects, uids, no facets): allocs/op 517 -> 502 (-2.90%, p=0.002) B/op 33.05Ki -> 32.55Ki (-1.52%, p=0.002) --- chunker/json_parser.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chunker/json_parser.go b/chunker/json_parser.go index 1905bf4b179..79bbafcf677 100644 --- a/chunker/json_parser.go +++ b/chunker/json_parser.go @@ -397,10 +397,13 @@ func getNextBlank() string { func (buf *NQuadBuffer) mapToNquads(m map[string]interface{}, op int, parentPred string) (mapResponse, error) { var mr mapResponse - // move all facets from global map to smaller mr.rawFacets map - mr.rawFacets = make(map[string]interface{}) + // move all facets from global map to smaller mr.rawFacets map. The vast majority + // of input objects have no facet keys, so allocate the map lazily on first hit. for k, v := range m { if strings.Contains(k, x.FacetDelimiter) { + if mr.rawFacets == nil { + mr.rawFacets = make(map[string]interface{}) + } mr.rawFacets[k] = v delete(m, k) } @@ -437,7 +440,7 @@ func (buf *NQuadBuffer) mapToNquads(m map[string]interface{}, op int, parentPred } } if uid > 0 { - mr.uid = fmt.Sprintf("%d", uid) + mr.uid = strconv.FormatUint(uid, 10) } }