Skip to content

refactor: remove virtual destructor from BasicIO to restore CRTP zero-overhead#2399

Open
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:opencode/remove-virtual-dtor-basicio
Open

refactor: remove virtual destructor from BasicIO to restore CRTP zero-overhead#2399
LHT129 wants to merge 1 commit into
antgroup:mainfrom
LHT129:opencode/remove-virtual-dtor-basicio

Conversation

@LHT129

@LHT129 LHT129 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Remove the unnecessary virtual destructor from BasicIO<IOTmpl> (CRTP base class) to eliminate the vptr overhead and restore the zero-overhead static polymorphism design.

Changes

  • src/io/basic_io.h: change virtual ~BasicIO() = default; to protected: ~BasicIO() = default;
  • Remove override keyword from all 7 subclass destructors:
    • MemoryIO, BufferIO, MMapIO, AsyncIO, ReaderIO, MemoryBlockIO, NonContinuousIO

Rationale

BasicIO uses CRTP for static polymorphism — all *Impl methods are dispatched via static_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

  • -8 bytes per IO object (vptr elimination)
  • Eliminates unnecessary virtual dispatch overhead
  • protected destructor prevents external deletion through base pointer at compile time

Fixes: #2397

Copilot AI review requested due to automatic review settings July 2, 2026 09:44
@LHT129 LHT129 added kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 version/1.0 labels Jul 2, 2026
@LHT129 LHT129 self-assigned this Jul 2, 2026
@mergify

mergify Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Require kind label

  • label~=^kind/

🟢 Require version label

  • label~=^version/

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 and protected to prevent deletion via base pointer.
  • Remove override from destructors across all BasicIO subclasses.

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.

Comment thread src/io/common/basic_io.h
Comment thread src/io/common/basic_io.h
@LHT129 LHT129 force-pushed the opencode/remove-virtual-dtor-basicio branch from 2dcfd4f to 55d0815 Compare July 3, 2026 02:32
Copilot AI review requested due to automatic review settings July 6, 2026 06:41
@LHT129 LHT129 force-pushed the opencode/remove-virtual-dtor-basicio branch from 55d0815 to 01ed293 Compare July 6, 2026 06:41
@vsag-bot

vsag-bot commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

/label S-waiting-on-review
/waiting-on reviewer
/request-review @jiaweizone
/request-review @wxyucs
/request-review @inabao

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/io/common/basic_io.h
…-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
@LHT129 LHT129 force-pushed the opencode/remove-virtual-dtor-basicio branch from 01ed293 to 3ec6331 Compare July 7, 2026 03:29
@pull-request-size pull-request-size Bot added size/M and removed size/S labels Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/improvement Optimizations, UX polish, or minor improvements 性能优化、体验打磨或细节改良 size/M version/1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: remove virtual destructor from BasicIO to restore CRTP zero-overhead

3 participants