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

[Bug]: Performance degradation observed in Ballerina version 2201.8.5 compared to 2201.8.4 #42402

Closed
gabilang opened this issue Mar 25, 2024 · 4 comments · Fixed by #42496 or #42518
Closed
Assignees
Labels
Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@gabilang
Copy link
Contributor

gabilang commented Mar 25, 2024

Description

A slowness is observed in the version 2201.8.5 when using fromJsonWithType() for binding a large json to a record. It's taking much time for conversion than 2201.8.4

Steps to Reproduce

import ballerina/io;
import ballerina/time;


public type Person record {
    int id;
    string name;
    int age;
    string address;
    string? email;
    string? contact;
    string qualification;
    boolean isEmployed;
    decimal salary;
    boolean married;
    string? spouse;
    string[]? children;
};

public function main() returns error? {
    json responseJson = check io:fileReadJson("./random_data.json");
    time:Utc startTime = time:utcNow();
    Person[] _ = check responseJson.fromJsonWithType();
    time:Utc endTime = time:utcNow();
    time:Seconds difference = time:utcDiffSeconds(endTime, startTime);
    io:println("Time taken to parse the JSON: ", difference);
}

Output with 2201.8.5 ->

Time taken to parse the JSON: 7.038689

Output with 2201.8.4 ->

Time taken to parse the JSON: 0.235574

random_data.json

No response

Affected Version(s)

No response

OS, DB, other environment details and versions

No response

Related area

-> Runtime

Related issue(s) (optional)

No response

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@gabilang gabilang added Type/Bug Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Mar 25, 2024
@gabilang gabilang self-assigned this Mar 25, 2024
@gabilang
Copy link
Contributor Author

gabilang commented Mar 25, 2024

Changes introduced with the PR #41936 caused this.
In the above PR, a fix has been introduced by making a shallow copy of unresolvedValues set, which can cause performance implications depending on the size of the unresolvedValues set.

@gabilang
Copy link
Contributor Author

The fix added with the PR #41936 tries to address the following problem.

import ballerina/io;

type Element record {|
    Element ...;
|};

type A record {|
    *Element;
|};

type B record {|
    *Element;
|};

type C record {|
    *Element;
    D d;
|};

type D record {|
    *Element;
    string display?;
|};

type U A|B|C;


public function main() returns error? {
    json val = {
        "d": {
            "display": "hello"
        }
    };

    U u = check val.cloneWithType();
    io:println(u);
}

which gives

error: {ballerina/lang.value}ConversionError {"message":"'map<json>' value cannot be converted to 'Element': 
                value of field 'display' adding to the record 'Element' should be of type 'Element', found '"hello"'"}

But, defining the type U as type U A|C|B; or type U C|A|B; is not giving the error.

@gabilang
Copy link
Contributor Author

gabilang commented Apr 22, 2024

With the introduced fix the observed average time taken for conversion is 0.223682.

Copy link

This issue is NOT closed with a proper Reason/ label. Make sure to add proper reason label before closing. Please add or leave a comment with the proper reason label now.

      - Reason/EngineeringMistake - The issue occurred due to a mistake made in the past.
      - Reason/Regression - The issue has introduced a regression.
      - Reason/MultipleComponentInteraction - Issue occured due to interactions in multiple components.
      - Reason/Complex - Issue occurred due to complex scenario.
      - Reason/Invalid - Issue is invalid.
      - Reason/Other - None of the above cases.

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 Type/Bug
Projects
Archived in project
1 participant