Skip to content

Feat/small pimpl#700

Merged
Alex2772 merged 7 commits intodevelopfrom
feat/small-pimpl
Feb 20, 2026
Merged

Feat/small pimpl#700
Alex2772 merged 7 commits intodevelopfrom
feat/small-pimpl

Conversation

@Alex2772
Copy link
Copy Markdown
Collaborator

small pimpl that might be required by #666.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @Alex2772, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant new utility, small_pimpl, designed to enhance performance and reduce dynamic memory allocations for PIMPL (Pointer to Implementation) idioms. By intelligently deciding whether to store the implementation object on the stack or heap based on its size, it provides a more efficient alternative to std::unique_ptr for certain use cases. This change is accompanied by robust testing to ensure its correctness and reliability, and minor build system adjustments to integrate these new tests.

Highlights

  • New small_pimpl Utility: Introduced a new small_pimpl class template that provides a small buffer optimized PIMPL implementation. This utility stores the implementation object inline on the stack if its size is less than or equal to a specified StackSize, falling back to heap allocation for larger objects.
  • Automatic Storage Management: The small_pimpl automatically determines whether to allocate the concrete type on the stack or heap, optimizing for performance by avoiding dynamic allocations for small objects. It uses std::variant internally to manage storage and dispatch ownership/destructors.
  • Comprehensive Test Coverage: Added a dedicated test suite (SmallPimplTest.cpp) to thoroughly validate the small_pimpl functionality, including allocation decisions, method invocation, destructor calls, and correct handling of copy and move semantics for both stack-allocated and heap-allocated types.
  • Build System Update: Modified the .vscode/tasks.json configuration to include 'Tests' in the default build targets, ensuring that the newly added tests are part of the standard build process.
  • Documentation Formatting: Updated the documentation in APimpl.h to use a more modern Markdown-like list format for details sections, improving readability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .vscode/tasks.json
    • Added 'Tests' to the build targets for the 'build' task.
  • aui.core/src/AUI/Util/APimpl.h
    • Updated documentation formatting for list items from HTML <ul><li> to Markdown-style -.
  • aui.core/src/AUI/Util/SmallPimpl.h
    • Added small_pimpl class template for small buffer optimized PIMPL implementation.
    • Implemented internal ControlBlock for type erasure and handling of Interface* to T* conversions.
    • Provided StackAllocated and HeapAllocated internal structs for managing storage based on object size.
    • Defined constructors, copy/move semantics, and accessors (operator->, operator*, ptr()) for the small_pimpl.
  • aui.core/tests/SmallPimplTest.cpp
    • Added a new test file for small_pimpl functionality.
    • Included tests for allocation decisions (stack vs. heap) based on object size.
    • Verified correct invocation of methods through the small_pimpl interface using GMock.
    • Confirmed proper destructor calls for both stack and heap-allocated objects.
    • Tested copy and move semantics for various concrete types (copy-only, move-only).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

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

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 introduces a new small_pimpl utility, which provides a small buffer optimized PIMPL implementation, similar to std::unique_ptr but with optional inline storage for small objects. This is a valuable addition for optimizing memory usage and reducing heap allocations. The PR also includes comprehensive unit tests for the new utility, covering allocation decisions, method invocation, and copy/move semantics. Additionally, the Doxygen documentation in APimpl.h has been updated for better readability, and the build configuration has been extended to include tests.

During the review, I've identified a few issues related to pointer handling within the small_pimpl implementation and an incorrect assertion in the move test. Addressing these will ensure the correctness and robustness of the new utility.

@Alex2772
Copy link
Copy Markdown
Collaborator Author

/gemini review

Copy link
Copy Markdown

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

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 introduces a small_pimpl utility, which is a great addition for performance optimization. The implementation is well-structured, leveraging modern C++ features like std::variant for storage. However, I've identified a few critical issues concerning copy and move semantics, particularly within the StackAllocated implementation, and missing assignment operators which could lead to undefined behavior or compilation failures. I've provided detailed comments and suggestions to address these issues. Additionally, I've included a couple of minor suggestions to enhance the class's usability and style.

Alex2772 and others added 2 commits February 20, 2026 03:06
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Alex2772
Copy link
Copy Markdown
Collaborator Author

/home/alex2772/CLionProjects/aui/cmake-build-relwithdebinfo/bin/Benchmarks --benchmark_filter=.*
2026-02-20T02:56:27+03:00
Running /home/alex2772/CLionProjects/aui/cmake-build-relwithdebinfo/bin/Benchmarks
Run on (32 X 5086.18 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x16)
  L1 Instruction 32 KiB (x16)
  L2 Unified 512 KiB (x16)
  L3 Unified 32768 KiB (x2)
Load Average: 14.71, 6.43, 3.65
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
***WARNING*** ASLR is enabled, the results may have unreproducible noise in them.
----------------------------------------------------------------------------------------------------------
Benchmark                                                                Time             CPU   Iterations
----------------------------------------------------------------------------------------------------------
SmallPimpl_Allocation<aui::small_pimpl<ITest, 128>, SmallImpl>        2.12 ns         2.11 ns    333858259
SmallPimpl_Allocation<std::function<void()>, SmallImpl>               8.59 ns         8.55 ns     83463874
SmallPimpl_Allocation<aui::small_pimpl<ITest, 128>, MediumImpl>       3.22 ns         3.20 ns    220340695
SmallPimpl_Allocation<std::function<void()>, MediumImpl>              8.36 ns         8.33 ns     82877739
SmallPimpl_Allocation<aui::small_pimpl<ITest, 128>, BigImpl>          51.1 ns         50.7 ns     14034323
SmallPimpl_Allocation<std::function<void()>, BigImpl>                 52.6 ns         52.4 ns     12969600
SmallPimpl_Copy<aui::small_pimpl<ITest, 128>, SmallImpl>              4.24 ns         4.20 ns    166740471
SmallPimpl_Copy<std::function<void()>, SmallImpl>                     10.2 ns         10.1 ns     70236187
SmallPimpl_Copy<aui::small_pimpl<ITest, 128>, MediumImpl>             4.22 ns         4.20 ns    166158461
SmallPimpl_Copy<std::function<void()>, MediumImpl>                    10.7 ns         10.7 ns     69750309
SmallPimpl_Copy<aui::small_pimpl<ITest, 128>, BigImpl>                26.6 ns         26.5 ns     26582109
SmallPimpl_Copy<std::function<void()>, BigImpl>                       26.0 ns         25.9 ns     27228219
SmallPimpl_Invoke<aui::small_pimpl<ITest, 128>, SmallImpl>            1.16 ns         1.15 ns    609427092
SmallPimpl_Invoke<std::function<void()>, SmallImpl>                   1.20 ns         1.19 ns    598789144
SmallPimpl_Invoke<aui::small_pimpl<ITest, 128>, MediumImpl>           1.15 ns         1.15 ns    607650646
SmallPimpl_Invoke<std::function<void()>, MediumImpl>                  1.39 ns         1.38 ns    508979367
SmallPimpl_Invoke<aui::small_pimpl<ITest, 128>, BigImpl>              1.44 ns         1.42 ns    511851310
SmallPimpl_Invoke<std::function<void()>, BigImpl>                     1.17 ns         1.17 ns    597973846

@Alex2772 Alex2772 merged commit b9a8d4d into develop Feb 20, 2026
75 of 77 checks passed
@Alex2772 Alex2772 deleted the feat/small-pimpl branch February 20, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant