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

[javasrc2cpg] Clear JavaParser caches after AST creation #4489

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

xavierpinho
Copy link
Contributor

We reach out-of-memory exceptions when running consecutive scans (within the same process) and providing the so-called «inference jar paths» (--inference-jar-paths).

This can be observed if we run all javasrc2cpg unit-tests with some additional inference jar. In the following experiment, I've used the same 100MB .jar throughout unit-tests and the 8GB limit is quickly reached, precluding them from finishing.

Screenshot 2024-04-24 at 16 11 49

Poking around, it seems clear that each time an inference jar is loaded its TypeSolver remains in memory.

By clearing JavaParser caches the situation improves considerably:

Screenshot 2024-04-24 at 16 16 14

@xavierpinho xavierpinho added java Relates to javasrc2cpg performance Improves the performance of Joern labels Apr 24, 2024
Copy link
Collaborator

@DavidBakerEffendi DavidBakerEffendi left a comment

Choose a reason for hiding this comment

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

Similar to the issue we encountered in Ruby with the ANTLR cache. Interesting find!

Copy link
Contributor

@max-leuthaeuser max-leuthaeuser left a comment

Choose a reason for hiding this comment

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

Maybe we should make AstCreationPass here a Releasable and use Using (https://www.scala-lang.org/api/3.4.1/scala/util/Using$.html) to clean up stuff (cleanupDelombokOutput, clearJavaParserCaches)

Also this PR needs to be merged with master once #4490 is in.

@xavierpinho xavierpinho force-pushed the xavierp/clear-javaparser-instances branch from 30de7c4 to b564995 Compare April 25, 2024 08:51
@xavierpinho xavierpinho merged commit ce5b8a4 into master Apr 25, 2024
5 checks passed
@xavierpinho xavierpinho deleted the xavierp/clear-javaparser-instances branch April 25, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java Relates to javasrc2cpg performance Improves the performance of Joern
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants