-
Notifications
You must be signed in to change notification settings - Fork 768
Reduce memory usage of holding BIR and source files #44185
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
base: master
Are you sure you want to change the base?
Reduce memory usage of holding BIR and source files #44185
Conversation
f9ab7a3
to
f9e1492
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR reduces memory usage by holding BIR and source file contents as weak references and lazy-loading them when needed.
- Introduces abstract BIRPackageFile and StringTextDocument with eager and lazy variants.
- Updates ModuleContext to store BIR bytes in a WeakReference and adds a lazy reload path.
- Refactors document loading (ProjectFiles, GeneralFSPackageRepository, etc.) to use Supplier for on-demand file reading.
Reviewed Changes
Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
tests/ballerina-test-utils/src/main/java/org/ballerinalang/test/BCompileUtil.java | Update import and use BIRPackageFile getter for binary content |
misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java | Add Supplier import for lazy file loading |
compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/TextDocuments.java | Support lazy text document creation with Supplier |
compiler/ballerina-tools-api/src/main/java/io/ballerina/tools/text/StringTextDocument.java | Refactor to abstract base and implement eager/lazy variants |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/programfile/PackageFileWriter.java | Use BIRPackageFile getter for writing binary content |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/programfile/CompiledBinaryFile.java | Remove legacy BIRPackageFile inner class |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/programfile/BIRPackageFile.java | Introduce abstract BIRPackageFile with eager and lazy implementations |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/model/symbols/BPackageSymbol.java | Update import to new BIRPackageFile class |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/packaging/converters/FileSystemSourceInput.java | Change syntax tree loading to use lazy content supplier |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/writer/BIRBinaryWriter.java | Simplify references to BIRPackageFile constants |
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/BIRPackageSymbolEnter.java | Migrate definePackage to use ModuleContext and lazy BIRPackageFile |
compiler/ballerina-lang/src/main/java/org/ballerinalang/repository/fs/GeneralFSPackageRepository.java | Use supplier for lazy document loading |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/ProjectFiles.java | Refactor document loading to use Supplier |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/PackageConfigCreator.java | Use Supplier-based DocumentConfig for lazy content |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/DocumentData.java | Abstract DocumentData with eager and lazy subclasses |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/internal/BalaFiles.java | Refactor BalaFiles document loading to use lazy Supplier |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleDescriptor.java | Make moduleCompilationId() public for lazy BIR loader |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java | Store BIR bytes in WeakReference and add lazy loader |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/MdDocumentContext.java | Update to use Supplier-based DocumentConfig |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java | Refactor to use DocumentConfig abstraction for content |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentConfig.java | Introduce lazy DocumentConfig abstraction with Supplier |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeModifierManager.java | Create DocumentConfig with Supplier for modified docs |
compiler/ballerina-lang/src/main/java/io/ballerina/projects/CodeGeneratorManager.java | Use Supplier for generated document content |
Comments suppressed due to low confidence (3)
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/programfile/BIRPackageFile.java:41
- [nitpick] Class name 'EagerBirPackageFile' uses 'Bir' casing, but 'BIR' is treated as an acronym elsewhere. Rename to 'EagerBIRPackageFile' for consistency.
public static class EagerBirPackageFile extends BIRPackageFile {
compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/programfile/BIRPackageFile.java:61
- [nitpick] Class name 'LazyBirPackageFile' uses 'Bir' casing, but 'BIR' is an acronym. Consider renaming to 'LazyBIRPackageFile' to keep naming consistent.
public static class LazyBirPackageFile extends BIRPackageFile {
compiler/ballerina-lang/src/main/java/io/ballerina/projects/ModuleContext.java:76
- [nitpick] The constant name 'DEFAULT_BIR_BYTE' suggests a single byte but holds a byte array reference. Rename to 'DEFAULT_BIR_BYTES' or 'DEFAULT_BIR_BYTES_REF' for clarity.
private static final WeakReference<byte[]> DEFAULT_BIR_BYTE = new WeakReference<>(new byte[0]);
misc/ballerina-bindgen/src/main/java/org/ballerinalang/bindgen/utils/BindgenFileGenerator.java
Outdated
Show resolved
Hide resolved
compiler/ballerina-lang/src/main/java/io/ballerina/projects/DocumentContext.java
Show resolved
Hide resolved
a155ab8
to
e07f1fc
Compare
ded7822
to
f93722b
Compare
ee21e65
to
bf5aaa0
Compare
bf5aaa0
to
af08b01
Compare
ad014a5
to
d5912df
Compare
Purpose
Reduce memory usage of holding BIR and source files by holding them as weak references. If the actual values are GCed we will reload the file from disk seamlessly.
Also more aggressively prune negative atoms in
ListInhabited
Approach
Samples
Remarks
Check List