From 8d8107a8b4a7ea114fc1091c40d93701fcd06170 Mon Sep 17 00:00:00 2001 From: He-Pin Date: Sun, 24 May 2026 02:26:27 +0800 Subject: [PATCH] perf: precompute json import sorted order Motivation: Strict JSON imports produce immutable object trees with fixed keys. Rendering these imported JSON objects currently computes the sorted inline order lazily on first render, which shows up on realworld kube-prometheus output. Modification: When building strict JSON import objects with more than one key, precompute _sortedInlineOrder before publishing the cached object. Single-key objects keep the existing lazy/default path. Result: The cached JSON import object carries the same sorted order that rendering would compute later, reducing repeated render-time work without changing Jsonnet semantics. --- sjsonnet/src/sjsonnet/Importer.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sjsonnet/src/sjsonnet/Importer.scala b/sjsonnet/src/sjsonnet/Importer.scala index 0ddc7c78..e11eea6e 100644 --- a/sjsonnet/src/sjsonnet/Importer.scala +++ b/sjsonnet/src/sjsonnet/Importer.scala @@ -378,6 +378,8 @@ object CachedResolver { keyArray, memberArray ) + if (keyArray.length > 1) + obj._sortedInlineOrder = Materializer.computeSortedInlineOrder(keyArray, memberArray) obj._skipFieldCache = true obj }