Improve D&D registry normalization efficiency

This commit is contained in:
2026-08-09 02:26:49 +00:00
parent 2a75f40871
commit b70d9f77e3
5 changed files with 93 additions and 49 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"errors"
"reflect"
"strconv"
"strings"
"testing"
@@ -60,6 +61,23 @@ func TestNormalizePreparesOnlyExactDuplicatesAndRetainsSameNameAndNestedPlaces(t
}
}
func BenchmarkExactDuplicateGroupsManyDistinct(b *testing.B) {
records := make([]normalizedRecord, 1_000)
for index := range records {
records[index] = normalizedRecord{location: dnd.Location{
Name: "Location " + strconv.Itoa(index),
SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: index + 1, EndUnitID: index + 1}},
}}
}
b.ReportAllocs()
b.ResetTimer()
for iteration := 0; iteration < b.N; iteration++ {
if groups := exactDuplicateGroups(records); len(groups) != len(records) {
b.Fatalf("group count = %d, want %d", len(groups), len(records))
}
}
}
func TestNormalizeAppliesSafeAliasGroupAndUsesContextualInputs(t *testing.T) {
client := &recordingLocationNormalizerClient{response: `{"duplicate_groups":[{"members":["candidate-000001","candidate-000002"],"canonical":"candidate-000002"}]}`}
doc := semanticDocument()