Note that there are some explanatory texts on larger screens.

plurals
  1. POGuava Charmatcher static initialization slow
    text
    copied!<p>UPDATE: It looks like my 13.0.1 is calling code from this diffed CharMatcher.</p> <p><a href="http://code.google.com/p/guava-libraries/source/diff?spec=svn69ad96b719d7cd3d872a948d7454f17b816a21c2&amp;r=464b0cfab7c3b6713c35e6f3ae7426542668c77b&amp;format=side&amp;path=/guava/src/com/google/common/base/CharMatcher.java" rel="noreferrer">http://code.google.com/p/guava-libraries/source/diff?spec=svn69ad96b719d7cd3d872a948d7454f17b816a21c2&amp;r=464b0cfab7c3b6713c35e6f3ae7426542668c77b&amp;format=side&amp;path=/guava/src/com/google/common/base/CharMatcher.java</a></p> <p>I seem to be having an issue with Guava's Charmatcher. I am currently writing some JUnit tests and I am noticing the first test takes a bit of time (15+ seconds), but the future tests are all approximately the same (.3 seconds), with a majority of the tests running through the same code. </p> <p>My analysis of the code has pinpointed that the Charmatcher in Guava's library seems to be the culprit. It looks like there is a bit of static initialization code in CharMatcher that might be the true reason it is taking so long. Is there any way I can disable or optimize this behavior? Is there something I am missing from the wiki pages or help files?</p> <p>Guava version 13.0.1, System: Linux 64, Eclipse 3.6.1</p> <p>EDIT: I built a test app with the following code:</p> <pre><code>import com.google.common.base.CharMatcher; public class Main { public static void main(String[] args) { // Using system instead of stopwatch to isolate library. long startTime = System.currentTimeMillis(); CharMatcher.is(' '); long endTime = System.currentTimeMillis(); System.out.println("took " + String.valueOf(endTime-startTime) + " ms"); startTime = System.currentTimeMillis(); CharMatcher.is('d'); endTime = System.currentTimeMillis(); System.out.println("2nd took " + String.valueOf(endTime-startTime) + " ms"); } } </code></pre> <p>This resulted in the following output:</p> <pre><code>took 15945 ms 2nd took 0 ms </code></pre> <p>I ran this in eclipse minus the JUnit framework and just google's guava library. Also I packaged an executable char and received similar results. I'll come back with a second edit after I run a profiler through it.</p> <p>Thanks for any help.</p> <p>Edit 2: Results from profiling:</p> <pre><code>Main.main(String[]) 22,556 ms com.google.common.base.CharMatcher.&lt;clinit&gt;() 22.556 ms com.google.common.base.CharMatcher.precomputed() 22,550 ms com.google.common.base.Platform.precomputeCharMatcher(CharMatcher) 22,550 ms com.google.common.base.CharMatcher.precomputedInternal() 22,550 ms com.google.common.base.CharMatcher.slowGetChars() 13,638 ms com.google.common.base.CharMatcher.setBits(CharMatcher$LookupTable) 8,911 ms </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload