Skip to content

perf: add AliasResolver caching and use batch saves consistently#33

Merged
Soner (shyim) merged 2 commits intomainfrom
perf/alias-resolver-cache-and-batch-writes
Feb 2, 2026
Merged

perf: add AliasResolver caching and use batch saves consistently#33
Soner (shyim) merged 2 commits intomainfrom
perf/alias-resolver-cache-and-batch-writes

Conversation

@shyim
Copy link
Copy Markdown
Member

Summary

  • Add resolve cache to AliasResolver to avoid repeated string concatenation when resolving the same type multiple times
  • Convert remaining indexers to use BatchSaveItems for consistency and reduced transaction overhead

Changes

AliasResolver Caching (alias_resolver.go)

  • Added resolveCache map to cache resolved type names
  • First lookup resolves and caches, subsequent lookups return cached value
  • Avoids repeated string concatenation (namespace + "\\" + typeName)

Batch Saves

  • TwigIndexer: Convert SaveItem to BatchSaveItems for twig files
  • ExtensionIndexer: Convert both indexBundle and indexApp to use BatchSaveItems

Benchmark Results

BenchmarkResolveType-16            	 9838870	       117.9 ns/op	       0 B/op	       0 allocs/op
BenchmarkResolveTypeRepeated-16    	100000000	        10.36 ns/op	       0 B/op	       0 allocs/op

Cache hits are ~11x faster than the mixed workload (10ns vs 117ns), with 0 allocations.

Testing

go test ./...
golangci-lint run

All tests pass, no lint issues.

- Add resolve cache to AliasResolver to avoid repeated string concatenation
- Convert TwigIndexer.indexTwig to use BatchSaveItems
- Convert ExtensionIndexer to use BatchSaveItems for bundles and apps
- Add benchmarks for AliasResolver.ResolveType

Cache hits are ~11x faster than uncached lookups (10ns vs 117ns).
- Add Reset() method to clear resolver state for reuse
- Add aliasResolverPool to reuse resolvers across file parses
- Use sentinel value for lastNamespace to ensure first Reset() is called
- Clear resolveCache when returning resolver to pool
@shyim Soner (shyim) merged commit dc88a8d into main Feb 2, 2026
3 checks passed
@shyim Soner (shyim) deleted the perf/alias-resolver-cache-and-batch-writes branch February 2, 2026 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant