Memory leak in compiler due to duplicated entries in typeCache map #31132
Labels
Area/SemanticAPI
Semantic API Related Issues #Compiler
Priority/Blocker
Team/CompilerFETools
Semantic API, Formatter, Shell
Type/Bug
Milestone
Description:
$subject was found when we analyzed the heap usage of the jballerina-tools distribution built from
2.0.0-alpha5-dev
branch (commit: 8241385) for the following scenario:Adding and deleting newlines to a source file in googleapis.calendar module [1]. Some of the dependencies were not there in the local cache so the package showed diagnostics for the unresolved modules (since the LS is run offline).
When we kept adding/deleting newlines we found out that the retained bytes increased significantly for
org.wso2.ballerinalang.compiler.util.Name
[2]. When analyzing further with @pubudu91 we figured out that the memory leak is due to duplicated entries in thetypeCache
map resulting in unnecessarily heldBSymbol
objects.Steps to reproduce:
Duplication of entries can be reproduced with ballerina-lang as follows:
io.ballerina.projects.test.TestBuildProject
[3]:TypesFactory.getInstance(project.projectEnvironmentContext().getService(CompilerContext.class)).typeCache
for each iteration and you can observe it growingAffected Versions:
At least Alpha 5.4
OS, DB, other environment details and versions:
Tested on Ubuntu 20.04
[1] https://github.com/ballerina-platform/module-ballerinax-googleapis.calendar
[2] https://github.com/ballerina-platform/ballerina-lang/blob/master/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/util/Names.java
[3] https://github.com/ballerina-platform/ballerina-lang/blob/master/project-api/project-api-test/src/test/java/io/ballerina/projects/test/TestBuildProject.java
The text was updated successfully, but these errors were encountered: