-
Notifications
You must be signed in to change notification settings - Fork 93
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
Improve memory with Integer (see #389) #392
Conversation
@fbricon please review this PR. I improve memory to use int instead of Integer. Here the result with Integer (existing code): Here the result with int (this PR): We win more of 1GB at start (almost 2GB). I'm waiting for accept of this PR to create an another PR to improve memory leak. |
InputStream in = DOMParserPerformance.class.getResourceAsStream("/xml/nasa.xml"); | ||
String text = convertStreamToString(in); | ||
TextDocument document = new TextDocument(text, "nasa.xml"); | ||
// Parse every time the big file with DOM parser. |
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.
Continuously parses the large nasa.xml file with the DOM parser
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.
@fbricon updated
import org.eclipse.lsp4xml.dom.DOMParser; | ||
|
||
/** | ||
* This utility class is used to check memories with use of {@link DOMParser} |
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.
This utility class is used to check the memory usage of {@link DOMParser}, loading the large nasa.xml file
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.
@fbricon updated
} | ||
} | ||
|
||
static String convertStreamToString(InputStream is) { |
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.
move to utility class to avoid duplication with XMLScannerPerformance (or create AbstractPerformanceProbe class)
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.
@fbricon updated
import org.eclipse.lsp4xml.dom.parser.XMLScanner; | ||
|
||
/** | ||
* This utility class is used to check memories with use of {@link XMLScanner} |
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.
This utility class is used to check the memory usage of {@link XMLScanner}, loading the large nasa.xml file
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.
@fbricon updated
d6c73e0
to
deb9b24
Compare
* @param is the input stream | ||
* @return the given input stream in a String. | ||
*/ | ||
public static String convertStreamToString(InputStream is) { |
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.
Scanner is autocloseable and its close() method automatically closes the source, so you can simplify this to:
public static String convertStreamToString(InputStream is) {
try (Scanner s = new java.util.Scanner(is)) {
s.useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
}
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.
@fbricon updated
* | ||
* @param is the input stream | ||
* @return the given input stream in a String. | ||
*/ |
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.
Please also remove the convertStreamToString implementation in DOMDocumentTest
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.
Good catch. I did that but not pushed. Sorry. It should be fixed now.
public class IOUtils { | ||
|
||
/** | ||
* Convert the given input stream in a String. |
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.
Convert the given {@link InputStream} into a String.
The source InputStream will then be closed.
Add scanner & parser main test performance + use int instead of using Integer. Signed-off-by: azerr <azerr@redhat.com>
deb9b24
to
7c14064
Compare
Thanks @fbricon for your review |
This PR adds scanner & parser main test performance and use int instead of using Integer to gain 1GB with big file like nasa.xml.
Signed-off-by: azerr azerr@redhat.com