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

Reducing a map performance worsens as the map gets bigger #34128

Closed
rpkamp opened this issue Dec 5, 2021 · 0 comments · Fixed by #34189
Closed

Reducing a map performance worsens as the map gets bigger #34128

rpkamp opened this issue Dec 5, 2021 · 0 comments · Fixed by #34189
Assignees
Labels
Points/3 Equivalent to three days effort Priority/High Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug

Comments

@rpkamp
Copy link

rpkamp commented Dec 5, 2021

Description:
Reducing a map (i.e. (map<int>).reduce()) decreases in performance as the size of map increases.

Steps to reproduce:

Build and run the following:

public function main() returns error? {
    map<int> m = {};

    foreach int i in 0 ..< 60000 {
        m[i.toString()] = i;
    }

    int sum = m.reduce(function (int carry, int value) returns int {
        return carry + value;
    }, 0);

    io:println(sum);
}

On my machine (Intel Core i7-1165G7) running this takes 20.44 seconds (as measured with time java -jar demo.jar)

For comparison, consider the following equivalent:

public function main() returns error? {
    map<int> m = {};

    foreach int i in 0 ..< 60000 {
        m[i.toString()] = i;
    }

    int sum = 0;
    foreach int j in m {
        sum += j;
    }
    
    io:println(sum);
}

This runs in 1.78 seconds (again, measured with time java -jar demo.jar), ~ 1 tenth of the .map speed.

The behaviour gets increasingly worse as 60000 is increased to higher values.
For example, with 100000 it takes 164.08 seconds, while the foreach variant requires only 2.21 seconds.

Affected Versions:

Swan Lake Beta 5

OS, DB, other environment details and versions:

Linux: Fedora 34 (Linux fedora 5.15.5-100.fc34.x86_64 #1 SMP Fri Nov 26 00:52:21 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux)

openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment 18.9 (build 11.0.13+8)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.13+8, mixed mode, sharing)

Related Issues (optional):
N/A

Suggested Labels (optional):
N/A

Suggested Assignees (optional):
N/A

@rpkamp rpkamp added the Type/Bug label Dec 5, 2021
@warunalakshitha warunalakshitha added Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Priority/High labels Dec 6, 2021
@warunalakshitha warunalakshitha added the Points/3 Equivalent to three days effort label Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Points/3 Equivalent to three days effort Priority/High Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants