ZeNyfh / gigavibe-java-edition

Music + Media bot made in java using JDA and Lavaplayer.
GNU General Public License v3.0
8 stars 3 forks source link

Add regex precompilation #151

Closed ZeNyfh closed 3 months ago

ZeNyfh commented 3 months ago

Is your feature request related to a problem? Please describe. when str.split(String regex) is called, it will compile the regex and use it once, same goes for any matchers defined in commands.

Describe the solution you'd like move all these regexes into the parent class rather than running it in the method, and compile them there, an example being

public class blah blah {
    private static final Pattern pattern = Pattern.compile("XYZ");
    ... 

Additional context It is a small optimisation but its good practice to do this. I thought about this optimisation at random and did a little investigation into how str.split() worked

9382 commented 3 months ago

Is there actually a significant speed issue here that this causes? Cause if not, this feels like it's just looking for trouble and removes useful simplicity. I could see this being helpful for important or repeatedly used regexs, but otherwise no