Spark中使用多个正则循环匹配数据,速度慢的问题

uaParserConfigs 是正则的List,里边是格map对应的{"regex":"************"}

 JavaRDD<String> inputWords = lines.map(new Function<String, String>() {

           @Override
           public String call(String s) throws Exception {
               for(int size = 0;size<uaParserConfigs.size();size++){
                    Matcher matcher = Pattern.compile(uaParserConfigs.get(size).get("regex")).matcher(s);
                    if(matcher.find()){
                        return  new String(s+"1");
                    }
                }
               return new String(s + "0");
           }
       });

速度特别慢,每分钟才处理几百条数据,怎么提高性能或者有没有其他的解决方案。

https://www.cnblogs.com/guo-xiang/p/7247371.html

Pattern.compile(uaParserConfigs.get(size).get("regex")) 放外面