fix(grpc-client): add early returns to avoid redundant operations#7672
Merged
limingxinleo merged 11 commits intohyperf:masterfrom Dec 17, 2025
Merged
Conversation
- Add early return in start() method when client is already running - Add early return in init() method when already initialized - Prevents unnecessary lock acquisition and redundant checks
There was a problem hiding this comment.
Pull request overview
This PR adds early return optimizations to the GRPC client's initialization and startup flow to reduce unnecessary lock contention in concurrent scenarios. By checking the client state before attempting lock acquisition, the code can avoid the overhead of locking when the client is already in the desired state.
Key changes:
- Early return in
start()method when client is already running (lines 193-195) - Early return in
init()method when already initialized (lines 219-221)
Comments suppressed due to low confidence (1)
src/grpc-client/src/BaseClient.php:219
- The comment mentions "double-checked locking" but the pattern here is slightly different. The first check at line 219 is outside any lock, making it an unlocked pre-check optimization rather than traditional double-checked locking. Traditional double-checked locking refers to checking both before and after acquiring the lock. While the implementation is correct, the comment could be more precise by describing this as "early return optimization to avoid lock contention" or "unlocked pre-check before attempting lock acquisition".
$lockKey = sprintf('%s:init', spl_object_hash($this));
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…nt is already started
…ry check for running state
limingxinleo
approved these changes
Dec 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan