chenBright opened a new pull request, #3700:
URL: https://github.com/apache/brpc/pull/3700
### What problem does this PR solve?
Issue Number: resolve
Problem Summary:
`Agent::merge_global()` creates a temporary `shared_ptr` through the
conditional expression
` c ? c : combiner.lock()`, even though its result is bound to a const
reference. This adds
reference-count updates to every normal percentile write and causes
contention when multiple
threads update the same `LatencyRecorder`.
### What is changed and the side effects?
Changed:
- Accept the supplied owner by const reference and use separate branches to
avoid copying it.
- Preserve ownership through `weak_ptr::lock()` when no owner is supplied,
and skip the operation
if the combiner has expired.
Side effects:
- Performance effects: Removes redundant reference-count updates from the
normal percentile write path.
- Breaking backward compatibility: None.
Local benchmark results for writers sharing one LatencyRecorder:
| Writers | Before (ns/op) | After (ns/op) | Reduction |
|---|---:|---:|---:|
| 1 | 59.1 | 46.8 | 20.9% |
| 8 | 158.1 | 19.9 | 87.4% |
---
### Check List:
- Please make sure your changes are compilable.
- When providing us with a new feature, it is best to add related tests.
- Please follow [Contributor Covenant Code of
Conduct](https://github.com/apache/brpc/blob/master/CODE_OF_CONDUCT.md).
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]