[testng-dev] Not a bug, but might help

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Not a bug, but might help

ghegstrom
I am seeing out of memory issues with a particularly large XML report.

   [testng] Exception in thread "main" java.lang.OutOfMemoryError:
Java heap space
   [testng]       at java.util.Arrays.copyOf(Arrays.java:2882)
   [testng]       at
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:
100)
   [testng]       at
java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
   [testng]       at java.lang.StringBuilder.append(StringBuilder.java:
203)
   [testng]       at
org.testng.internal.Utils.escapeUnicode(Utils.java:548)
   [testng]       at
org.testng.internal.Utils.writeUtf8File(Utils.java:113)
   [testng]       at
org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:65)
   [testng]       at org.testng.TestNG.generateReports(TestNG.java:
1053)
   [testng]       at org.testng.TestNG.run(TestNG.java:1016)
   [testng]       at org.testng.TestNG.privateMain(TestNG.java:1301)
   [testng]       at org.testng.TestNG.main(TestNG.java:1265)
   [testng] The tests failed.

Looking at Utils.java, I noticed that escapeUnicode() has the
following line (543):
StringBuilder result = new StringBuilder();

I think the resulting string will always be at least as long as the
input string, so it seems like that line should be changed to:
StringBuilder result = new StringBuilder(s.Length());

That should prevent 17 or so reallocations and mem_copies when the
string is around 1 MB in size.

Of course, whether we should have a file that big is a different
question, and obviously I can increase the available memory, but
initializing the StringBuilder to a known size seems more efficient
regardless.

Thanks,
-Greg

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] Not a bug, but might help

Cédric Beust ♔-2
Hi Greg,

Thanks for the report. Did you actually verify that your suggestion fixes the problem? If yes, I'll apply it (or feel free to send me a pull request).

-- 
Cédric




On Tue, Aug 30, 2011 at 8:04 AM, ghegstrom <[hidden email]> wrote:
I am seeing out of memory issues with a particularly large XML report.

  [testng] Exception in thread "main" java.lang.OutOfMemoryError:
Java heap space
  [testng]       at java.util.Arrays.copyOf(Arrays.java:2882)
  [testng]       at
java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:
100)
  [testng]       at
java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
  [testng]       at java.lang.StringBuilder.append(StringBuilder.java:
203)
  [testng]       at
org.testng.internal.Utils.escapeUnicode(Utils.java:548)
  [testng]       at
org.testng.internal.Utils.writeUtf8File(Utils.java:113)
  [testng]       at
org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:65)
  [testng]       at org.testng.TestNG.generateReports(TestNG.java:
1053)
  [testng]       at org.testng.TestNG.run(TestNG.java:1016)
  [testng]       at org.testng.TestNG.privateMain(TestNG.java:1301)
  [testng]       at org.testng.TestNG.main(TestNG.java:1265)
  [testng] The tests failed.

Looking at Utils.java, I noticed that escapeUnicode() has the
following line (543):
StringBuilder result = new StringBuilder();

I think the resulting string will always be at least as long as the
input string, so it seems like that line should be changed to:
StringBuilder result = new StringBuilder(s.Length());

That should prevent 17 or so reallocations and mem_copies when the
string is around 1 MB in size.

Of course, whether we should have a file that big is a different
question, and obviously I can increase the available memory, but
initializing the StringBuilder to a known size seems more efficient
regardless.

Thanks,
-Greg

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.


--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.
Reply | Threaded
Open this post in threaded view
|

[testng-dev] Re: Not a bug, but might help

Michael Ondrejko
In reply to this post by ghegstrom
Have you tried out your suggestion and did it fix the issue? If so, in what version is the fix available?

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-dev/-/64FFvqvNSncJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-dev?hl=en.