Skip to content

ssa: prune abitypes by callgraph#1590

Open
visualfc wants to merge 3 commits intogoplus:mainfrom
visualfc:callgraph
Open

ssa: prune abitypes by callgraph#1590
visualfc wants to merge 3 commits intogoplus:mainfrom
visualfc:callgraph

Conversation

@visualfc
Copy link
Member

@visualfc visualfc commented Jan 27, 2026

  • prune abitypes by RTA callgraph ( needAbiInit disable prune )
func main() { fmt.Println("hello world") }

go build: 2358096
llgo build: 1840128
llgo prune (CHA) : 1313600
llgo prune (RTA) : 1287632 RTA has issues parsing the patch package
llgo prune (VTA) : 1194816 VTA has issues for generic type

@gemini-code-assist
Copy link

Summary of Changes

Hello @visualfc, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant optimization to the SSA (Static Single Assignment) phase by implementing ABI type pruning based on callgraph analysis. It leverages golang.org/x/tools/go/callgraph to identify methods that are not invoked within the program's execution flow. By doing so, the system can avoid generating unnecessary ABI metadata and function pointers for these unused methods, contributing to reduced binary size and improved efficiency.

Highlights

  • Callgraph Integration: Integrated golang.org/x/tools/go/callgraph for static analysis, specifically using VTA (Variable Type Analysis) and CHA (Class Hierarchy Analysis) to build callgraphs.
  • ABI Type Pruning: Implemented a new PruneAbiTypes mechanism that identifies and prunes uninvoked methods from ABI type metadata based on callgraph analysis, reducing generated code size.
  • Dynamic Method Generation: Refactored ABI type generation to conditionally include method function pointers. If a method is determined to be uninvoked by the callgraph, its corresponding function pointer in the ABI metadata can be set to Nil.
  • Enhanced ABI Symbol Tracking: Introduced an AbiSymbol struct to store more comprehensive information about ABI types, including the raw type, generated type, package path, and a count of uncommon methods (xcount), facilitating more granular pruning.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@xgopilot
Copy link
Contributor

xgopilot bot commented Jan 27, 2026

Code Review Summary

This PR introduces ABI type pruning via callgraph analysis to eliminate unused method references in the generated LLVM IR. The approach uses VTA (Variable Type Analysis) combined with CHA (Class Hierarchy Analysis) to determine which methods are actually invoked through interfaces.

Note: The PR title includes "[WIP]" indicating work in progress. The issues identified below should be addressed before removing this marker.

Key Observations

Strengths:

  • The optimization concept is sound - pruning unreachable method implementations can reduce binary size
  • Good use of established callgraph analysis tools from golang.org/x/tools

Areas Requiring Attention:

  • Commented-out code left in ssa/expr.go (debug artifact)
  • New AbiSymbol struct lacks documentation
  • Complex pruning logic in abiUncommonMethods could benefit from clarifying comments
  • The methodIsInvoke function iterates over all callgraph nodes for each method call, which may be expensive for large programs

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces callgraph-based ABI type pruning, which is a significant improvement for optimizing the generated code. The changes involve integrating golang.org/x/tools/go/callgraph for static analysis and modifying the ABI type generation logic to conditionally omit method entries that are not invoked. Overall, the approach seems sound for achieving the stated goal of pruning unused ABI types.

@xgopilot
Copy link
Contributor

xgopilot bot commented Jan 27, 2026

Code Review Summary

This PR implements ABI type pruning via callgraph analysis (VTA + CHA) to optimize method table generation. The approach is sound for reducing binary size by eliminating unused method pointers.

Key concerns:

  1. Performance: The methodIsInvoke function has O(N×E) complexity per lookup - consider building a lookup map once
  2. Nil safety: obj.Pkg() can return nil for universe-scope types in cl/compile.go
  3. WIP cleanup: Commented-out code in ssa/expr.go should be removed before merge

Note: Title indicates [WIP] - addressing these before final review is recommended.

@visualfc visualfc force-pushed the callgraph branch 10 times, most recently from 8b18d36 to 011a820 Compare January 29, 2026 03:31
@codecov
Copy link

codecov bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 97.82609% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.18%. Comparing base (e1c943d) to head (f029e42).

Files with missing lines Patch % Lines
ssa/abitype.go 97.18% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1590      +/-   ##
==========================================
+ Coverage   93.16%   93.18%   +0.01%     
==========================================
  Files          48       48              
  Lines       13314    13375      +61     
==========================================
+ Hits        12404    12463      +59     
- Misses        724      725       +1     
- Partials      186      187       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@visualfc visualfc force-pushed the callgraph branch 5 times, most recently from c8098ec to d9a7121 Compare February 2, 2026 12:53
@visualfc visualfc force-pushed the callgraph branch 6 times, most recently from a099b5c to 51519f4 Compare February 10, 2026 01:20
@visualfc visualfc changed the title [WIP] ssa: prune abitypes by callgraph ssa: prune abitypes by callgraph Feb 10, 2026
@visualfc visualfc force-pushed the callgraph branch 14 times, most recently from b63143c to 952fb10 Compare February 12, 2026 02:44
@visualfc visualfc force-pushed the callgraph branch 4 times, most recently from f6a08fc to 8cd9aa0 Compare March 1, 2026 23:17
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