diff --git a/lib/registry.js b/lib/registry.js index 2169b66f..97203eed 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -219,14 +219,16 @@ function formatLabels(labels) { ); } +const sharedLabelCache = new WeakMap(); function flattenSharedLabels(labels) { - if (labels.__flattened_internal) { - return labels.__flattened_internal; + const cached = sharedLabelCache.get(labels); + if (cached) { + return cached; } const formattedLabels = formatLabels(labels); const flattened = formattedLabels.join(','); - Object.defineProperty(labels, '__flattened_internal', { value: flattened }); + sharedLabelCache.set(labels, flattened); return flattened; } function escapeLabelValue(str) {