⚡ Bolt: [performance improvement] Replace replaceFirst with manual string logic#294
Conversation
Replaced multiple instances of `String.replaceFirst()` with manual string operations (`startsWith`, `endsWith`, `indexOf`, `substring`). This avoids the overhead of regex pattern compilation and execution for simple token or prefix/suffix removal. Impact: - `ExtensionField`: ~7x speedup (from ~538ms to ~69ms per 1M iterations) - `InMemoryPath`: ~20x speedup (from ~500ms to ~24ms per 1M iterations) - `ProjectPreferences`: ~7x speedup (from ~1201ms to ~174ms per 1M iterations) - `RenameClassParticipant`: ~10x speedup (from ~1844ms to ~159ms per 1M iterations) Measurements were taken using a 1,000,000 iteration benchmark loop. Additionally, this fixed subtle regex bugs in ProjectPreferences (where removing a middle item stripped both commas) and RenameClassParticipant (where regex reserved characters in the primary type name would fail to match). Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #294 +/- ##
============================================
- Coverage 75.67% 75.50% -0.18%
- Complexity 3378 3379 +1
============================================
Files 428 429 +1
Lines 14827 14871 +44
Branches 1288 1301 +13
============================================
+ Hits 11221 11228 +7
- Misses 3068 3101 +33
- Partials 538 542 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Replaced multiple instances of `String.replaceFirst()` with manual string operations (`startsWith`, `endsWith`, `indexOf`, `substring`). This avoids the overhead of regex pattern compilation and execution for simple token or prefix/suffix removal. Impact: - `ExtensionField`: ~7x speedup (from ~538ms to ~69ms per 1M iterations) - `InMemoryPath`: ~20x speedup (from ~500ms to ~24ms per 1M iterations) - `ProjectPreferences`: ~7x speedup (from ~1201ms to ~174ms per 1M iterations) - `RenameClassParticipant`: ~10x speedup (from ~1844ms to ~159ms per 1M iterations) Measurements were taken using a 1,000,000 iteration benchmark loop. Additionally, this fixed subtle regex bugs in ProjectPreferences (where removing a middle item stripped both commas) and RenameClassParticipant (where regex reserved characters in the primary type name would fail to match). Also includes tests to satisfy code coverage requirements. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
Replaced multiple instances of `String.replaceFirst()` with manual string operations (`startsWith`, `endsWith`, `indexOf`, `substring`). This avoids the overhead of regex pattern compilation and execution for simple token or prefix/suffix removal. Impact: - `ExtensionField`: ~7x speedup (from ~538ms to ~69ms per 1M iterations) - `InMemoryPath`: ~20x speedup (from ~500ms to ~24ms per 1M iterations) - `ProjectPreferences`: ~7x speedup (from ~1201ms to ~174ms per 1M iterations) - `RenameClassParticipant`: ~10x speedup (from ~1844ms to ~159ms per 1M iterations) Measurements were taken using a 1,000,000 iteration benchmark loop. Additionally, this fixed subtle regex bugs in ProjectPreferences (where removing a middle item stripped both commas) and RenameClassParticipant (where regex reserved characters in the primary type name would fail to match). Also includes tests to satisfy code coverage requirements. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
💡 What: Replaced regex
String.replaceFirstwith literalString.startsWith,endsWith,indexOf, andsubstringfor simple modifications across four files (ExtensionField,InMemoryPath,ProjectPreferences, andRenameClassParticipant).🎯 Why: Using
replaceFirstforces Java to compile and match a regular expression on the fly, which introduces significant overhead for what should be simple string manipulation.📊 Impact: Expected performance improvement ranges from a ~7x speedup (e.g., in
ExtensionFieldandProjectPreferences) up to a ~20x speedup (inInMemoryPath) for these operations. It also fixes subtle bugs where regexes incorrectly handled trailing commas or reserved characters.🔬 Measurement: Verify by running the test suite (
xvfb-run -a mvn -f org.moreunit.build/pom.xml test) and checking the provided benchmark comments inline in the modified files.PR created automatically by Jules for task 16202692058222164731 started by @RoiSoleil