Peter Boughton
Peter Boughton

Reputation: 112160

What optimisations can I expect java.util.regex to perform?

Does Java perform any regex optimisations; if so, what are they?

I'm interested in both optimisations at the regex engine level, and more general usage-level optimisations.

(For example, in some other languages, commonly used regexes are cached to avoid re-compiling, but what I've read so far implies that Java doesn't do this automatically?)

To be clear:
I'm not asking for how to optimise the actual regular expressions themselves. I'm asking about actions that might happen automatically, inside the regex engine.

Upvotes: 1

Views: 180

Answers (1)

Gunslinger47
Gunslinger47

Reputation: 7061

According to the source code for java.util.regex.Pattern, the compile() method doesn't attempt any cache optimizations.

Near the end, there is a code comment that points out the use of peephole optimization.

Upvotes: 2

Related Questions