From efd4d702d5426d7a31cdf3727d5d8f102cad6196 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Sun, 16 Mar 2025 01:11:01 -0700 Subject: [PATCH] perf: use append instead of Concat in appendLookupLocations This reduces alloc/GC churn as append in theory can expand a slice without having to copy the original. Loosely this appears to massively improve performance inside ResolveModuleName. --- internal/compiler/module/cache.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/compiler/module/cache.go b/internal/compiler/module/cache.go index f826be84db..d689118e35 100644 --- a/internal/compiler/module/cache.go +++ b/internal/compiler/module/cache.go @@ -1,7 +1,6 @@ package module import ( - "slices" "strings" "sync" @@ -96,9 +95,9 @@ func (c *resolutionCache[T]) appendLookupLocations(resolved T, failedLookupLocat c.mu.Lock() defer c.mu.Unlock() lookupLocations := c.lookupLocations[resolved] - lookupLocations.FailedLookupLocations = slices.Concat(lookupLocations.FailedLookupLocations, failedLookupLocations) - lookupLocations.AffectingLocations = slices.Concat(lookupLocations.AffectingLocations, affectingLocations) - lookupLocations.ResolutionDiagnostics = slices.Concat(lookupLocations.ResolutionDiagnostics, resolutionDiagnostics) + lookupLocations.FailedLookupLocations = append(lookupLocations.FailedLookupLocations, failedLookupLocations...) + lookupLocations.AffectingLocations = append(lookupLocations.AffectingLocations, affectingLocations...) + lookupLocations.ResolutionDiagnostics = append(lookupLocations.ResolutionDiagnostics, resolutionDiagnostics...) } type perDirectoryResolutionCache[T any] struct {