oracle / graaljs

A ECMAScript 2023 compliant JavaScript implementation built on GraalVM. With polyglot language interoperability support. Running Node.js applications!
Universal Permissive License v1.0
1.7k stars 185 forks source link

Performance degradation when moving to GraalJS 23.1.1 (and GraalVM for JDK21) #779

Open efimbakulin opened 8 months ago

efimbakulin commented 8 months ago

Hey!

After moving our project to the latest version of GraalVM its performance degraded drastically (up to 2 times). The internal logic of the project is quite complex, but I've prepared a synthetic test showing the performance difference between GraalVM 22.3.3 and GraalVM for JDK21. The test simply makes a bunch of calls to the jsonParseStringify() function defined as follows:

const OBJECT_SIZE = 500;
const obj = {};

for (let i = 0; i < OBJECT_SIZE; i++) {
    obj["double_key" + i] = Math.random();
    obj["str_key" + i] = '#'.repeat(50);
};

function jsonParseStringify() {
    return JSON.parse(JSON.stringify(obj));
};

module.exports = {
    jsonParseStringify
};

It gives the following numbers in case of GraalVM 22.3.3

warming up
....................................................................................................
Iterations: 100000
Duration: 125.514641
Score: 796.719788 ops/second

testing
....................................................................................................
Iterations: 10000
Duration: 12.805132
Score: 780.936890 ops/second

and the following ones in case of GraalVM JDK21:

warming up
....................................................................................................
Iterations: 100000
Duration: 157.155243
Score: 636.313477 ops/second

testing
....................................................................................................
Iterations: 10000
Duration: 15.578632
Score: 641.904846 ops/second

The complete project may be found here https://github.com/efimbakulin/graalvm-jdk21-performance-test

Could you please give it a look? Probably there are some options which should be enabled to improve the things?

efimbakulin commented 4 months ago

Hi!

Many thanks for the improvements already done. The numbers looks much better, although they are not as good as for 22.3.3.

Here are my new measurements:

22.3.3

warming up
....................................................................................................
Iterations: 100000
Duration: 123.946686
Score: 806.798523 ops/second
testing
....................................................................................................
Iterations: 10000
Duration: 12.107336
Score: 825.945496 ops/second

JDK21 (23.1.1)

warming up
....................................................................................................
Iterations: 100000
Duration: 141.798828
Score: 705.224426 ops/second
testing
....................................................................................................
Iterations: 10000
Duration: 14.073600
Score: 710.550232 ops/second

24.1.0-SNAPSHOT (commit 39b63b9a2202e1c10248357161ea5e63e2934792)

warming up
....................................................................................................
Iterations: 100000
Duration: 127.519096
Score: 784.196289 ops/second
testing
....................................................................................................
Iterations: 10000
Duration: 12.662384
Score: 789.740723 ops/second

To run the test against 24.1.0-SNAPSHOT, I invoked the following commands within the GraalJS repository:

mx build
mx maven-install --repo <M2_REPO_ROOT> --only GRAALJS --version-string 23.1.1

Here, M2_REPO_ROOT denotes the root of the .m2 repository used to test GraalJS version 23.1.1. After that I rerun the test for GraalJS 23.1.1 using the newly built GraalJS jar files.

Is that enough or do I need to install some additional artifacts?

Thanks.