MDEV-34848 Remove overhead from unnecessary MDL_context_owner inheritance#4808
MDEV-34848 Remove overhead from unnecessary MDL_context_owner inheritance#4808kevdn wants to merge 2 commits intoMariaDB:mainfrom
Conversation
Instead of using abstract MDL_context_owner* interface, use THD* directly to avoid virtual function call overhead in MDL wait loops. The MDL subsystem only interacts with THD objects, so using THD* directly eliminates unnecessary virtual function calls for enter_cond, exit_cond, is_killed, and notify_shared_lock.
There was a problem hiding this comment.
Pull request overview
This PR refactors parts of the MDL/THD interaction by switching several APIs from the MDL_context_owner* abstraction to direct THD* usage.
Changes:
- Updated
notify_shared_lock()to takeTHD*instead ofMDL_context_owner*and adjusted call sites/implementation accordingly. - Updated
MDL_wait::timed_wait()andMDL_contextownership plumbing to useTHD*directly. - Simplified a few
get_thd()-mediated field accesses (e.g.,rgi_slave,thd_is_connected).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| sql/sql_class.h | Changes THD::notify_shared_lock() signature to accept THD*. |
| sql/sql_class.cc | Adjusts THD::notify_shared_lock() implementation for new parameter type. |
| sql/mdl.h | Updates MDL_context_owner::notify_shared_lock(), MDL_wait::timed_wait(), and MDL_context owner storage/accessors to use THD*. |
| sql/mdl.cc | Updates MDL_wait::timed_wait() implementation and related THD accesses for the new THD* owner type. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
FooBarrior
left a comment
There was a problem hiding this comment.
I would actually prefer the opposite: architecturally, we should focus on decomposing thd, because it's bloated.
I understand though, that we might want to make de-architecturizing optimizations, if it's worth it.
If this is supposed to be a such, is there any benchmark demonstrating the commitment?
- Update documentation comments to reflect THD* usage - Remove redundant ctx_in_use alias in notify_shared_lock() - Add note about backward compatibility of MDL_context_owner interface Co-Authored-By: kevdn <lehuukhoa12@gmail.com>
|
Agree with @FooBarrior . For the unmeasurable performance benefit of removing virtual function we'll plant this THD dependency everywhere. We should actually de-THD as much as we can, it is too important class, which purpose nobody can explain well. |
gkodinov
left a comment
There was a problem hiding this comment.
Thank you for working on this! This is a preliminary review.
First, on the technicalities: Please squash your two commits into a single one and provide a commit message to it that compiles with CODING_STANDARDS.md.
Secondly, I kind of agree with the two developers that have commented that you need a strong case to remove layering like you did. A benchmark or profile info would help. And even in that case, there probably are alternatives to removing a base class for THD.
|
Said the above, I see mysql/mysql-server@b9766fe68bab as a step towards a wrong direction and I'm happy to see it reverted. I won't blindly buy the "performance benefit of removing virtual function". But still I see it as a valid encapsulation cleanup and it must make |
svoj
left a comment
There was a problem hiding this comment.
Looks, nice. A few requests inline.
|
|
||
| /** | ||
| @note This interface is kept for backward compatibility. | ||
| The MDL subsystem now uses THD* directly for better performance. |
There was a problem hiding this comment.
What kind of backward compatibility? No, please remove it altogether.
|
|
||
|
|
||
| bool THD::notify_shared_lock(MDL_context_owner *ctx_in_use, | ||
| bool THD::notify_shared_lock(THD *ctx_in_use, |
There was a problem hiding this comment.
Please rename it to in_use, such that you don't have to update the rest of the method.
| bool notify_shared_lock(MDL_context_owner *ctx_in_use, | ||
| bool notify_shared_lock(THD *ctx_in_use, | ||
| bool needs_thr_lock_abort, | ||
| bool needs_non_slave_abort) override; |
There was a problem hiding this comment.
You claim that you de-virtualized MDL_context_owner methods, but you didn't. You have to remove inheritance from MDL_context_owner and remove override keyword from all relevant methods.
Optimize MDL by using THD* directly instead of using abstract MDL_context_owner* interface, use THD* directly to avoid virtual function call overhead in MDL wait loops.
The MDL subsystem only interacts with THD objects, so using THD* directly eliminates unnecessary virtual function calls for enter_cond, exit_cond, is_killed, and notify_shared_lock.