dnrajugade / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

CharMatcher static init is long #1192

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
CharMatcher does a lot of work in static init, including creating a 65k element 
(where elements are "bits") and calling CharMatcher.match() for every codepoint 
on a complex matcher.

The worst offender is:

public static final CharMatcher INVISIBLE = 

...

 .precomputed();

which does the aforementioned work.  This takes maybe 50ms in the best base, 
but can take > 10 seconds in pathological cases, as described here:

http://stackoverflow.com/questions/13143401/guava-charmatcher-static-initializat
ion-slow

People who never use the static members of CharMatcher, or even who never use 
CharMatcher at all (but it gets indirectly referred to by other Guava code) pay 
this price.

In addition to speeding up the underlying table creation (perhaps with an 
optimized, non-fluent version of the matchers for things like INVISIBLE), it 
would be great if these singletons were created lazily, so you don't pay the 
cost until they are used - very useful for things like INVISIBLE which are 
probably rarely used. This could be accomplished by having a char matcher which 
internally delegates to some underlying matcher, but constructs the underlying 
lazily.

Original issue reported on code.google.com by travis.d...@gmail.com on 6 Nov 2012 at 3:18

GoogleCodeExporter commented 9 years ago
What it does is is pretty bad indeed. We're on it.

Original comment by kevinb@google.com on 7 Nov 2012 at 1:36

GoogleCodeExporter commented 9 years ago

Original comment by kak@google.com on 7 Nov 2012 at 1:44

GoogleCodeExporter commented 9 years ago
Submitted internally; should be mirrored out soonish.

Original comment by lowas...@google.com on 7 Nov 2012 at 5:06

GoogleCodeExporter commented 9 years ago
We might want to explain what we fixed.  Is all precomputing() lazy now?

Original comment by kevinb@google.com on 30 Jan 2013 at 7:08

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:13

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08