-
Notifications
You must be signed in to change notification settings - Fork 851
Perf: replace dynamic_cast with static_cast in this_thread() #6281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Are we never going to introduce any other subclasses? |
|
Derive another class from |
|
I personally don't have the plan, but it is possible as long as we have Thread as a abstract class. If someone introduced XThread, it can be accidentally used as EThread with your change. I think the objective of the function is not only the cast but also to check if we are on EThread. If you call it on XThread you cannot get an object, and this prevents the misuse. |
|
I'm not sure if this is faster than dynamic_cast, but I'd say ok if the change was like this. |
|
Do you mean In another function or class, I agree with adding some guards or use
|
oknet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The this_thread() and this_ethread() should be wrap functions for pthread_getspecific() and just apply static_cast for the returned void * object. It is not necessary to perform dynamtic_cast on it.
maskit
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If simple static_cast is what we need then I'm fine with it, but the behavior doesn't match with the comment in I_Thread.h. The comment have to be updated too.
|
Also, I'm not saying we should keep abstract |
|
I think that we can't give up on performance for a use case that may or may not exist. If we have alternative approaches to achieve the same without impacting performance, we should do that; otherwise, this PR is good. I also agree that we can remove the Thread class, but I do not think that is the goal of this PR. |
I don't think so. Mismatch of comment and implementation will cause confusion. I think the comment in I_Thread.h should have been updated regardless of #6288. |
|
Cherry-picked to v9.0.x branch. |
During the investigation of HTTP/2 performance regression, I realized that this
dynamic_casthas a significant impact (~6%).We never initialize
Threaddirectly, so we don't need to usedynamic_casthere.