RegExp object - performance issues in some cases

Marcus Lagergren marcus.lagergren at oracle.com
Sat Sep 27 08:06:04 UTC 2014


Tomas - Thank’s a lot for the report

Nashorn uses the Joni regexp engine, used by e.g. JRuby as well. It is known to be pretty fast
as far as these things go. 

I’ve filed a bug to investigate this.
It might be the case that something else is causing the problem when the regexp is set up.

The bug is: https://bugs.openjdk.java.net/browse/JDK-8059312

Regards
Marcus


On 27 Sep 2014, at 09:20, Tomáš Machálek <tomas.machalek at gmail.com> wrote:

> Recently I've been trying to rewrite my project to be compatible with
> Nashorn (instead of older Rhino). And I've found some interesting
> performance issues regarding regular expressions.
> 
> It appears that object version (RegExp) with case insensitivity enabled
> performs quite bad compared to Rhino and similar variants in Nashorn (see
> the code below):
> 
> // ------------- variant 1 - RegExp object, case insensitive search: (6.0
> sec) ------
> function srchStuff(s) {
>    return RegExp('foo', 'i').exec(s);
> }
> for (i = 0; i < 5000; i += 1) {
>    srchStuff('lorem ipsum dolor sit amet');
> }
> 
> // ------ variant 2 - RegExp object, case sensitive search (0.2 sec) -----
> function srchStuff(s) {
>    return RegExp('foo').exec(s);
> }
> for (i = 0; i < 5000; i += 1) {
>    srchStuff('lorem ipsum dolor sit amet');
> }
> 
> // ------ variant 3 - literal form (0.1 sec) ------------------
> function srchStuff(s) {
>    return /foo/i.exec(s);
> }
> for (i = 0; i < 5000; i += 1) {
>    srchStuff('lorem ipsum dolor sit amet');
> }
> 
> // in Rhino, all the variants seem to take about the same time (~ 0.15sec)
> 
> I know the sample represents quite a bad code as it can be easily optimized
> (pattern is static -> there is no need to instantiate RegExp again and
> again). But in a real-case scenario the 'srchStuff()' can be part of some
> external library function I need to call multiple times and then problem
> arises.
> 
> Does anybody experienced the same problem? Or is there something I am
> missing?
> 
> 
> Thank you,
> Tomas



More information about the nashorn-dev mailing list