From 88859f3cd80e03f695cba5462d959949ff9a5583 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Wed, 1 Sep 2021 12:42:35 -0700 Subject: [PATCH] cmd/compile: optimize unified IR handling of imported functions This CL skips reading of imported function bodies except from the local package or for inlining. Previously, we wasted a bunch of CPU and memory by reading in normal function bodies for all imported functions and methods. Change-Id: I0b3df3f4a3e2819117dac11a1f9e4526288c14d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/347030 Trust: Matthew Dempsky Run-TryBot: Matthew Dempsky TryBot-Result: Go Bot Reviewed-by: Cuong Manh Le --- src/cmd/compile/internal/noder/reader.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go index 17ccb25e1d..204d25bce8 100644 --- a/src/cmd/compile/internal/noder/reader.go +++ b/src/cmd/compile/internal/noder/reader.go @@ -920,6 +920,12 @@ func (r *reader) addBody(fn *ir.Func) { pri := pkgReaderIndex{r.p, r.reloc(relocBody), r.dict} bodyReader[fn] = pri + if fn.Nname.Defn == nil { + // Don't read in function body for imported functions. + // See comment in funcExt. + return + } + if r.curfn == nil { todoBodies = append(todoBodies, fn) return