Skip to content

Conversation

@bnbajwa
Copy link
Contributor

@bnbajwa bnbajwa commented Nov 4, 2025

Eliminates dynamic allocations

The Log class now attempts to acquire a buffer from this pool before falling back to dynamic allocation. Various logger implementations (NullLogger, StdLogger, SysLogger, AsyncLogger) are updated to return the buffers to the pool after use.

SDB-10043

@bnbajwa bnbajwa requested a review from a team as a code owner November 4, 2025 15:19
@gemini-code-assist
Copy link

Summary of Changes

Hello @bnbajwa, 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 implements a buffer pooling strategy for log messages to significantly reduce dynamic memory allocations, thereby improving logging performance and reducing memory fragmentation. By reusing pre-allocated message buffers, the system avoids the overhead of frequent new/delete calls during high-volume logging, contributing to a more efficient and stable application.

Highlights

  • Introduced Log Buffer Pool: A boost::lockfree::stack is now used to manage a pool of LogMsgPtr buffers, pre-allocating 8 buffers at startup to reduce dynamic memory allocations.
  • Eliminated Dynamic Allocations in Log Creation: The Log constructor now attempts to pop a buffer from the log_buf_pool. If the pool is empty, it falls back to LogStream::make_storage() for dynamic allocation.
  • Returned Buffers to Pool: All logger implementations (NullLogger, StdLogger, SysLogger, AsyncLogger, and TestLogger) are updated to push the LogMsgPtr back into the log_buf_pool after processing, ensuring buffer reuse.
  • Header Refactoring: Logger.hpp now declares the LogBufPool type and its accessor function, and header includes have been reordered for better organization.
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

@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 buffer pool for logging to eliminate dynamic memory allocations on the hot path. This is achieved by using a boost::lockfree::stack as a pool of log buffers. The Log class now attempts to acquire a buffer from this pool before falling back to dynamic allocation. Various logger implementations (NullLogger, StdLogger, SysLogger, AsyncLogger) are updated to return the buffers to the pool after use. The changes are correct and well-implemented. My review includes a couple of suggestions to replace magic numbers related to pool configuration with named constants to improve code readability and maintainability.

@bnbajwa bnbajwa force-pushed the log branch 4 times, most recently from 51f7af3 to c41df3c Compare November 5, 2025 14:52
@markaylett markaylett requested a review from Copilot November 5, 2025 18:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a lock-free buffer pool for log message storage to reduce dynamic memory allocations during logging operations. The pool pre-allocates log buffers and reuses them across log operations.

  • Introduces a global LogBufPool using boost::lockfree::stack with a capacity of 64 buffers
  • Updates all logger implementations to return buffers to the pool after use
  • Modifies the Log constructor to attempt to acquire a buffer from the pool before allocating new storage

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
toolbox/sys/Logger.hpp Adds LogBufPool type alias and log_buf_pool() function declaration; reorganizes includes
toolbox/sys/Logger.cpp Implements the buffer pool with initialization, adds buffer return logic to all logger implementations
toolbox/sys/Log.ut.cpp Updates test logger to return buffers to the pool
toolbox/sys/Log.hpp Modifies Log constructor to attempt to acquire buffers from the pool before allocating

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Eliminates dynamic allocations

SDB-10043
@bnbajwa bnbajwa enabled auto-merge (rebase) November 6, 2025 13:54
@bnbajwa bnbajwa merged commit fd7346f into reactivemarkets:master Nov 6, 2025
5 checks passed
@bnbajwa bnbajwa deleted the log branch November 6, 2025 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants