Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize CodeGen for executable jar #41449

Conversation

Thushara-Piyasekara
Copy link
Contributor

@Thushara-Piyasekara Thushara-Piyasekara commented Sep 26, 2023

Purpose

Depends on #42433 and #42792.

The Ballerina compiler currently includes all imported modules in their entirety within the final executable JAR. However, these modules may contain unused constructs that bloat the final size. This project proposes an optimization to remove these unused parts, resulting in several benefits:

  • Smaller final executable JAR: Reduced file size improves storage efficiency and distribution.
  • Faster GraalVM native image build: Less code translates to quicker build times.
  • Smaller GraalVM native image executable: A more compact native image improves deployment efficiency.
  • Potential startup time improvements: A smaller executable might lead to faster program startup.

This project is driven by the substantial benefits it brings to GraalVM native image builds. We've achieved significant improvements in both build time (up to 15.95% faster) and executable size (up to 20.9% smaller). See the attached performance comparison in the Samples section for detailed results.

Approach

We implemented a two-tier Optimization Architecture for this project,

  1. Ballerina Codegen Optimization: The Ballerina code generation process is optimized to eliminate unused constructs like functions and type definitions. The current implementation filters the unused constructs after the BIRGen phase.

Codegen Optimization Diagram

  1. Native Dependency Optimization: During final JAR creation, the final executable JAR is optimized at the bytecode level, currently targeting JVM bytecode classes. This phase optimizes the platform dependency JARs used by ballerina packages.

Native Dependency Optimization Diagram

Further implementation details can be found here.

Samples

GraalVM build time comparision

Refer to GraalVM native build time and performance comparison for more details.

Remarks

  • Only unused functions and type definitions are optimized for ballerina source derived code.
  • Bytecode level optimization is done in ".class" file level.

Check List

  • Read the Contributing Guide
  • Updated Change Log
  • Checked Tooling Support (#)
  • Added necessary tests
    • Unit Tests
    • Spec Conformance Tests
    • Integration Tests
    • Ballerina By Example Tests
  • Increased Test Coverage
  • Added necessary documentation
    • API documentation
    • Module documentation in Module.md files
    • Ballerina By Examples

@CLAassistant
Copy link

CLAassistant commented Sep 26, 2023

CLA assistant check
All committers have signed the CLA.

@Thushara-Piyasekara Thushara-Piyasekara changed the title Add CodeGen optimization for fat jar Add CodeGen optimization for executable jar Oct 2, 2023
@Thushara-Piyasekara Thushara-Piyasekara changed the title Add CodeGen optimization for executable jar Optimize CodeGen for executable jar Oct 2, 2023
Copy link
Member

@heshanpadmasiri heshanpadmasiri left a comment

Choose a reason for hiding this comment

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

Looks better now just a few minor nits.

Copy link

This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the stale label is removed or commented.

@github-actions github-actions bot added the Stale label Jul 13, 2024
@Thushara-Piyasekara
Copy link
Contributor Author

Closing because the implementation was merged to a separate branch in #43013. All future pull requests related to this feature will be sent to that branch.

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.