Skip to content

runtime: speed up funcinfo hot paths#2010

Closed
cpunion wants to merge 23 commits into
xgo-dev:mainfrom
cpunion:codex/runtime-funcinfo-hotpath
Closed

runtime: speed up funcinfo hot paths#2010
cpunion wants to merge 23 commits into
xgo-dev:mainfrom
cpunion:codex/runtime-funcinfo-hotpath

Conversation

@cpunion

@cpunion cpunion commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Depends on #2009.

Performance follow-up for compact runtime funcinfo. This PR narrows hot-path overhead after entry-PC materialization and adds a reusable comparison benchmark.

Changes

  • Stop treating runtime.FuncForPC as a caller-frame tracking API. Funcinfo metadata is still emitted, but FuncForPC-only packages no longer get caller-frame / pcline instrumentation.
  • Add a page index for runtime PC-line records so synthetic-PC and CallersFrames line lookups avoid a full-table binary search.
  • Prefer the funcinfo entry table before native symbol lookup for function-value PCs.
  • Make the FuncForPC cache 4-way associative to avoid direct-mapped cache thrashing across many function-value PCs.
  • Add benchmark/runtime_funcinfo for repeatable cross-branch runtime funcinfo performance and size comparisons.

Validation

  • macOS: go build -o /tmp/llgo-2010-fixed-final ./cmd/llgo
  • macOS: go test ./benchmark/runtime_funcinfo
  • macOS: go test ./cl -run 'FuncForPC|CallerFrame|RuntimeCaller|Pcline|FuncInfo'
  • macOS: go test ./test/go -run 'TestRuntime(LineInfoAndStack|FuncInfoConcurrentFirstUse|StatementLineInfo)' -count=1
  • macOS: benchmark runner, 7 process runs, -iters=200000 -packages=12 -methods=12

Cells are best/trimmed avg. Runtime metrics use ns/us. multipkg.*Many is one batch over 144 target functions.

macOS Performance

metric go main #2002 #2009 this PR
hot.Caller0 153/153.8ns 9.6/9.9us 52/54ns 51/52.2ns 52/52.6ns
hot.Caller1 171/173.4ns 6/6.4us 79/83.8ns 82/83.2ns 83/83.6ns
hot.CallersOnly 126/127.2ns 14.5/15.1us 183/191.8ns 177/181.2ns 182/185ns
hot.CallersFramesFirst 269/271.2ns n/a 521/540.4ns 518/525.4ns 528/536.2ns
hot.FuncForPCEntry 13/13ns n/a 8/8ns 8/8ns 8/8.6ns
hot.FuncFileLineEntry 9/9.6ns n/a 10/10.4ns 10/10ns 10/10ns
multipkg.DeepRun 3.6/3.7us 138.5/139us 7.3/7.4us 7.1/7.5us 5.9/6us
multipkg.FuncForPCMany 2.7/2.8us n/a 145.1/147.8us 859.1/861us 949/975.4ns
multipkg.FileLineMany 8.4/8.7us n/a 145.1/147.3us 853.3/859.7us 1.2/1.3us
stdlib.Caller0 141/146.8ns 14.9/15us 53/62.6ns 51/58ns 72/77.2ns
stdlib.CallersFramesFirst 415/427.6ns n/a 651/667.6ns 584/626ns 778/798.6ns
stdlib.FuncForPCEntry 14/15.8ns n/a 7/7.4ns 7/7ns 7/8ns

macOS LTO Spot Check

metric this PR this PR + LTO
multipkg.DeepRun 6.1/6.2us 5.2/5.2us
multipkg.FuncForPCMany 956/986ns 238/256.7ns
multipkg.FileLineMany 1.3/1.3us 359/372.3ns

LTO Scaling Sanity

targets FuncForPCMany + LTO FileLineMany + LTO
36 54/65ns 102/106ns
144 244/249ns 360/362ns
576 867/902ns 1.3/1.4us

macOS Size

scenario go main #2002 #2009 this PR
hot 2.3 MiB 1.8 MiB 2.1 MiB 2.1 MiB 2.1 MiB
deep 2.3 MiB 1.8 MiB 2.1 MiB 2.1 MiB 2.1 MiB
multipkg 2.4 MiB 2.0 MiB 2.3 MiB 2.3 MiB 2.3 MiB
stdlib 5.0 MiB 3.4 MiB 3.7 MiB 3.8 MiB 3.8 MiB

@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 57.18109% with 480 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
benchmark/runtime_funcinfo/main.go 0.00% 468 Missing ⚠️
cl/instr.go 97.51% 8 Missing and 4 partials ⚠️

📢 Thoughts on this report? Let us know!

@cpunion cpunion marked this pull request as draft July 1, 2026 15:46
@cpunion

cpunion commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #2012/#2016: the Go-1.26-style funcinfo port replaced this hot-path line of work wholesale (same goals, measured at or beyond these numbers in the #2016 matrix). Review continues on #2012 + #2016.

@cpunion cpunion closed this Jul 2, 2026
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