refactor: remove virtual destructor from BasicIO to restore CRTP zero-overhead#2399
refactor: remove virtual destructor from BasicIO to restore CRTP zero-overhead#2399LHT129 wants to merge 1 commit into
Conversation
Merge Protections🟢 All 2 merge protections satisfied — ready to merge. Show 2 satisfied protections🟢 Require kind label
🟢 Require version label
|
There was a problem hiding this comment.
Code Review
This pull request refactors the BasicIO class and its derived classes by replacing the public virtual destructor in BasicIO with a protected, non-virtual destructor. Consequently, the override specifier has been removed from the destructors of all derived classes, including AsyncIO, BufferIO, MemoryIO, and others. This design change prevents polymorphic deletion while eliminating virtual table overhead. There are no review comments, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because no GitHub Actions runner was available. Make sure your repository has a runner available to run Copilot's review, or add a copilot-setup-steps.yml file specifying one with the runs-on attribute. See the docs for more details.
Refactors the CRTP BasicIO<IOTmpl> base class to remove its virtual destructor (and corresponding override destructors in derived classes) in order to eliminate vptr overhead and restore zero-overhead static polymorphism.
Changes:
- Make
BasicIO’s destructor non-virtual andprotectedto prevent deletion via base pointer. - Remove
overridefrom destructors across allBasicIOsubclasses.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/io/basic_io.h | Makes BasicIO destructor protected and non-virtual, removing vptr/virtual dispatch. |
| src/io/reader_io.h | Removes override from ReaderIO destructor to match non-virtual base. |
| src/io/noncontinuous_io.h | Removes override from NonContinuousIO destructor to match non-virtual base. |
| src/io/mmap_io.h | Removes override from MMapIO destructor declaration. |
| src/io/memory_io.h | Removes override from MemoryIO inline destructor. |
| src/io/memory_block_io.h | Removes override from MemoryBlockIO destructor declaration. |
| src/io/buffer_io.h | Removes override from BufferIO inline destructor. |
| src/io/async_io.h | Removes override from AsyncIO destructor declaration. |
2dcfd4f to
55d0815
Compare
55d0815 to
01ed293
Compare
|
/label S-waiting-on-review |
…-overhead BasicIO uses CRTP for static polymorphism, so all *Impl methods are dispatched via static_cast. The virtual destructor was the only virtual dispatch in the hierarchy, introducing an unnecessary vptr (8 bytes) per IO object. Changes: - Change virtual ~BasicIO() = default to protected non-virtual destructor - Remove override keyword from all 7 subclass destructors: MemoryIO, BufferIO, MMapIO, AsyncIO, ReaderIO, MemoryBlockIO, NonContinuousIO Signed-off-by: LHT129 <tianlan.lht@antgroup.com> Assisted-by: OpenCode:qwen3.7-plus
01ed293 to
3ec6331
Compare
Summary
Remove the unnecessary
virtualdestructor fromBasicIO<IOTmpl>(CRTP base class) to eliminate the vptr overhead and restore the zero-overhead static polymorphism design.Changes
src/io/basic_io.h: changevirtual ~BasicIO() = default;toprotected: ~BasicIO() = default;overridekeyword from all 7 subclass destructors:MemoryIO,BufferIO,MMapIO,AsyncIO,ReaderIO,MemoryBlockIO,NonContinuousIORationale
BasicIOuses CRTP for static polymorphism — all*Implmethods are dispatched viastatic_cast<IOTmpl&>(*this). The virtual destructor was the only virtual function in the hierarchy, introducing an unnecessary vptr (8 bytes) per IO object. No IO object is ever deleted through a base pointer, so the virtual destructor serves no purpose.Impact
protecteddestructor prevents external deletion through base pointer at compile timeFixes: #2397