Graal: Memory leak in js code using hashmaps and high cardinality properties

Created on 29 Nov 2018  路  12Comments  路  Source: oracle/graal

Memory leak in graal RC9 for code using javascript hash maps and high-cardinality properties like that:

const UUID = Packages.java.util.UUID;

setInterval(() => {
    const a = {};
    a[UUID.randomUUID().toString()] = 1;
}, 1);

Memory starts growing until the heap is completely exhausted. This is a show stopper for most js applications.

graaljs-heapdump

bug javascript

Most helpful comment

Thank you, Andreas, again! I confirm that RC14 passes our memory leak tests. So I'm closing this issue for now.

All 12 comments

Hi @victor-smirnov

thanks for your report. The problem seems to be that our object model fails to detect this case and stores the keys in its transition map without ever collecting them. Our methods to prevent exactly that fail to to catch this specific case.

A workaround until we fix this is not to use random properties on objects; you could use a more array-like structure or use an ES6 Map object.

Best,
Christian

Thank you, Christian!

Unfortunately, all applications parsing real-life json files (JSON.parse()) are affected, because of unbounded cardinality of real-life data. Memory just doesn't leak so fast as with using UUIDs. For micro-benchmarks running on GraalVM we can avoid using problematic constructions, but it seems there is no workaround for existing data-processing applications.

Regards,
Victor

Are there any updates on this issue? Multiple RCs have been released (up to RC13 now) and I have to agree with Victor that most real-world use of Javascript would be affected by some way. In particular, this would include parsing arbitrary JSON or using Javsacript APIs that treat a Javascript object as a dictionary instead of using ES6 Map.

We're very excited and loving Graal but this is a showstopper for us.

Well that's embarrassing! I was doing some unrelated testing and posted under the wrong identity. I wrote the preceding comment.

And I thought you have a really good bot that almost talks like you ;).

@wirthi Can you post an update?

This issue will be fixed in RC14. Sorry for the delay.

Thank you for the excellent news and the very prompt response. I was only worried because of the time delay since the initial response in December.

It looks like it didn't ship in RC14. Should we expect it in RC15?

The fix shipped in RC14 (forgot to mention it in the changelog).

Please give it a try.

Thank you very much! We're excited to try this out and the new libgraal.

Thank you Andreas! :)

Thank you, Andreas, again! I confirm that RC14 passes our memory leak tests. So I'm closing this issue for now.

Was this page helpful?
0 / 5 - 0 ratings