You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "matthiasblaesing (via GitHub)" <gi...@apache.org> on 2023/02/03 22:24:40 UTC
[GitHub] [netbeans] matthiasblaesing commented on pull request #5315: Moved Pattern.compile() stage to class level
matthiasblaesing commented on PR #5315:
URL: https://github.com/apache/netbeans/pull/5315#issuecomment-1416481734
I agree with with @mbien without clear arguments where performance is improved this must not be merged.
This change hurts readability of the code as the declarations of the pattern and the use-site are hundreds of lines apart. The non-speaking names are an additional pain point, which make them a no-go. A declaration like `Pattern p = Pattern.compile` is fine a local context, where the use site is a few lines away and it is obvious what happens. With class level constants this needs to be better.
For the performance: @mbien pointed to the memory impact. A compiled pattern is held in memory, raising GC pressure as statics are not collected. Yes you will argue, that it is tiny and so I will argue, that most probably my CPU won't get a millikelvin warmer just because it has to recompile a `Pattern`. As @mbien already pointed out, this changes if you find situation where a something like this is done (this is a tight loop):
```java
for(int i = 0; i < LARGE_NUMER; i++) {
Pattern p = Pattern.compile("CONSTANTSTRING"),
}
```
For this `p` can be pulled out of the loop without affecting readability, while improving performance. These cases are rare.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists