Add benchmarks, improve performance of Message::parse()#132
Conversation
samdark
commented
Jan 24, 2026
| Q | A |
|---|---|
| Is bugfix? | ❌ |
| New feature? | ❌ |
| Breaks BC? | ❌ |
| Fixed issues | - |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #132 +/- ##
=========================================
Coverage 99.33% 99.33%
- Complexity 161 162 +1
=========================================
Files 11 11
Lines 449 451 +2
=========================================
+ Hits 446 448 +2
Misses 3 3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds PhpBench benchmarks and a small optimization to reduce overhead in Message::parse() when no placeholders are present.
Changes:
- Added PhpBench benchmark suites for
Messageparsing andLogger::log()behavior. - Optimized
Message::parse()with an early return when the message has no{characters. - Introduced PhpBench tooling/configuration via
composer.jsonscripts andphpbench.json.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Benchmark/MessageBench.php | Adds benchmarks covering common placeholder parsing scenarios. |
| tests/Benchmark/LoggerBench.php | Adds logger benchmarks for simple and placeholder messages. |
| src/Message.php | Adds a fast-path to skip regex work when no placeholders exist; simplifies the regex literal. |
| phpbench.json | Configures PhpBench runner defaults and benchmark discovery path. |
| composer.json | Adds PhpBench as a dev dependency and a bench script entry. |
| CHANGELOG.md | Records the enhancement in release notes (currently with a placeholder issue number). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| { | ||
| $message = (string) $message; | ||
|
|
||
| if (!str_contains($message, '{')) { |
There was a problem hiding this comment.
If there are no placeholders at all, which is quite common, do not run preg_replace_callback(). Gives about a 10—13% performance increase.
There was a problem hiding this comment.
Has preg_replace_callback() been replaced with strtr()?
|
To continue, we need to merge #133 |
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>