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 #43013

Conversation

Thushara-Piyasekara
Copy link
Contributor

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

Thushara-Piyasekara and others added 30 commits August 6, 2023 20:01
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.

We'll merge this to feature branch and then merge it the master separately

@heshanpadmasiri heshanpadmasiri merged commit 44eb092 into ballerina-platform:feature-codegen-optimizer Jul 8, 2024
16 of 18 checks passed
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