From 159bd6ac0c8984fbe0a5f4a69741dbb339d13bcb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 29 Oct 2026 12:32:02 -0700 Subject: [PATCH] Split link store lookups into inlineable fast paths LinkStore.Get and PagedLinkStore.Get are called on nearly every checker link access, and almost all of those calls hit an existing entry. Both methods also contained the code to create the entry (allocating the map or growing the page list, allocating a page, and allocating the value from the arena), which made them too large for the Go compiler to inline, so every hit paid for a full call. Move the creation logic into out-of-line getSlow methods so that Get only does the lookup and falls back to getSlow on a miss. The goal is for the hit path to be inlined at call sites: LinkStore.Get now fits within the default inlining budget, and the smaller PagedLinkStore.Get body is cheaper to inline at the hot call sites that PGO selects. Co-authored-by: Steven Chong <25894545+teamchong@users.noreply.github.com> --- tsc/internal/core/linkstore.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tsc/internal/core/linkstore.go b/tsc/internal/core/linkstore.go index 1866a1a2638f2..4c01b25de8a49 100644 --- a/tsc/internal/core/linkstore.go +++ b/tsc/internal/core/linkstore.go @@ -12,14 +12,17 @@ type LinkStore[K comparable, V any] struct { } func (s *LinkStore[K, V]) Get(key K) *V { - value := s.entries[key] - if value != nil { + if value := s.entries[key]; value != nil { return value } + return s.getSlow(key) +} + +func (s *LinkStore[K, V]) getSlow(key K) *V { if s.entries == nil { s.entries = make(map[K]*V) } - value = s.arena.New() + value := s.arena.New() s.entries[key] = value return value } @@ -49,6 +52,13 @@ type PagedLinkStore[V any] struct { } func (s *PagedLinkStore[V]) Get(key uint64) *V { + if link := s.TryGet(key); link != nil { + return link + } + return s.getSlow(key) +} + +func (s *PagedLinkStore[V]) getSlow(key uint64) *V { pageIndex := key >> LinkPageShift if int(pageIndex) >= len(s.pages) { // Grow the length of the list to pageIndex+1