Skip to content

go/ssa: skip Selection.Type in MethodValue for non-generic methods - #674

Open
hungcs wants to merge 1 commit into
golang:masterfrom
hungcs:ssa-methodvalue-fast-path
Open

go/ssa: skip Selection.Type in MethodValue for non-generic methods#674
hungcs wants to merge 1 commit into
golang:masterfrom
hungcs:ssa-methodvalue-fast-path

Conversation

@hungcs

@hungcs hungcs commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Follow-up to CL 826224 (the #81308 memory fix). That fix stopped the
per-selection Signatures from being retained, but they were still allocated:
MethodValue materializes sel.Type() for every (type, method) pair, and on
large programs the churn is real GC load.

When the method has no type parameters of its own, a ground receiver can't
leave free type parameters in the selection type, so the receiver-only check
is equivalent and nothing needs to be materialized. Generic methods keep the
full canonicalized check.

Makes deadcode ~8% faster on a benchmark of kubernetes/cmd/kubelet
(7.15s to 6.55s)

Updates golang/go#81308

When a method has no type parameters of its own, substituting a ground
receiver cannot introduce free type parameters, so the selection type is
parameterized iff the receiver is, and the receiver-only check suffices.
Only generic methods need the full check on the materialized (and
canonicalized, see CL 826224) selection type.

Selection.Type allocates a new Signature on every call, and MethodValue
runs for every (type, method) pair the method-set machinery reaches, so
on large programs the allocation churn is significant GC load: on a
1,132-package monorepo with no generic methods, whole-program analysis
drops from 296s to 210s wall (findings identical), close to the 186s
that x/tools v0.45.0 needed before generic-method support.

Updates golang/go#81308
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: dbdd830) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/tools/+/827325.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Hung-wei Chuang:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/827325.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Hung-wei Chuang:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/827325.
After addressing review feedback, remember to publish your drafts!

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.

2 participants