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

Improve memory with Integer (see #389) #392

Merged
merged 1 commit into from
May 27, 2019
Merged

Conversation

angelozerr
Copy link
Contributor

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 [email protected]

@angelozerr
Copy link
Contributor Author

angelozerr commented May 27, 2019

@fbricon please review this PR. I improve memory to use int instead of Integer.

Here the result with Integer (existing code):

image

Here the result with int (this PR):

image

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.
Copy link
Contributor

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

Copy link
Contributor Author

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}
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

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)

Copy link
Contributor Author

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}
Copy link
Contributor

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

Copy link
Contributor Author

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.
*/
public static String convertStreamToString(InputStream is) {
Copy link
Contributor

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() : "";
		}
	}

Copy link
Contributor Author

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.
*/
Copy link
Contributor

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

Copy link
Contributor Author

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.
Copy link
Contributor

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 <[email protected]>
@angelozerr angelozerr merged commit b69c38e into master May 27, 2019
@angelozerr
Copy link
Contributor Author

Thanks @fbricon for your review

@angelozerr angelozerr deleted the memory-improvement branch May 27, 2019 14:04
@angelozerr angelozerr restored the memory-improvement branch May 27, 2019 15:21
@angelozerr angelozerr deleted the memory-improvement branch May 28, 2019 00:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants