MinicraftPlus / minicraft-plus-revived

Minicraft+, an extension of Notch's original minicraft project, with tons more features.
GNU General Public License v3.0
456 stars 92 forks source link

Update some code handling strings where performance issues occur #688

Open BenCheung0422 opened 1 month ago

BenCheung0422 commented 1 month ago

This improves a little performance issue. Here, Double#parseDouble is used to validate whether the input is double. It can be problematic as it throws exceptions when the input is invalid while the input is invalid most of the time. It is known that creation of exceptions are expensive due to the creations of stack traces. This pull request changes it to regex matching, though I doubt there would be an entry of number with localization enabled.

1~5% performance improvement is already significant when CPU time can be reduced. This kind of use cases (using methods with exceptions) will be carefully assessed when it can affect performance, in the code optimization task in the near future.

BenCheung0422 commented 1 month ago

Furthermore, I have found another method with some performance issue (tested by browsing text-based displays): image Fixed by: image Reference: https://stackoverflow.com/a/35242882