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

Reduce memory taken during compilation #41510

Merged

Conversation

Nadeeshan96
Copy link
Contributor

@Nadeeshan96 Nadeeshan96 commented Oct 12, 2023

Purpose

Describe the problems, issues, or needs driving this feature/fix and include links to related issues.

This PR reduces the memory taken during compilation by means of the following.

  1. Cleans up the BIR after the code generation phase.
  2. Do not cache the TextDocument instance of dependent modules.
  3. Remove BLangPackages of dependent modules after the code generation phase.

Fixes #41384
Fixes #41407

Approach

Describe how you are implementing the solutions along with the design details.

Samples

Provide high-level details about the samples related to this feature.

Remarks

List any other known issues, related PRs, TODO items, or any other notes related to the PR.

With Ballerina 2201.7.3 version without these changes the following code took about 900 MB memory for the heap at average when compiling the code for the first time.

import ballerina/io as _;
import ballerinax/health.fhir.r4 as _;
import ballerinax/health.fhir.r4.international401 as _;
import ballerinax/health.hl7v2 as _;
import ballerinax/health.hl7v2.utils.v2tofhirr4 as _;
import ballerinax/health.hl7v23 as _;
import ballerinax/health.hl7v2commons as _;

public function main() returns error? {}

With these changes introduced on top of that it takes about 700 MB memory for the heap at average when compiling the code for the first time.

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

@Nadeeshan96 Nadeeshan96 added the Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime label Oct 12, 2023
@Nadeeshan96 Nadeeshan96 mentioned this pull request Oct 12, 2023
13 tasks
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (7d548e5) 76.71% compared to head (68d25fa) 76.72%.
Report is 1 commits behind head on master.

Files Patch % Lines
...allerinalang/compiler/bir/codegen/JvmValueGen.java 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master   #41510   +/-   ##
=========================================
  Coverage     76.71%   76.72%           
+ Complexity    52667    52662    -5     
=========================================
  Files          2880     2879    -1     
  Lines        198580   198566   -14     
  Branches      25801    25797    -4     
=========================================
+ Hits         152334   152342    +8     
+ Misses        37812    37789   -23     
- Partials       8434     8435    +1     

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

@Nadeeshan96 Nadeeshan96 marked this pull request as ready for review October 12, 2023 16:44
@Nadeeshan96 Nadeeshan96 changed the title Clean up BIR after codegen phase Reduce memory taken during compilation Oct 16, 2023
HindujaB
HindujaB previously approved these changes Oct 27, 2023
Copy link
Contributor

@HindujaB HindujaB left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@warunalakshitha warunalakshitha left a comment

Choose a reason for hiding this comment

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

LGTM

@warunalakshitha warunalakshitha merged commit ad0ab92 into ballerina-platform:master Nov 23, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime
Projects
None yet
4 participants