Skip to content

Reduce bloat due to statics#519

Merged
dennisklein merged 1 commit into
FairRootGroup:devfrom
ktf:reduce-statics
Jan 7, 2025
Merged

Reduce bloat due to statics#519
dennisklein merged 1 commit into
FairRootGroup:devfrom
ktf:reduce-statics

Conversation

@ktf

@ktf ktf commented Jan 7, 2025

Copy link
Copy Markdown
Contributor

Avoid disseminating every compile unit including Message.h with TransportNames and
TransportTypes and the associated unordered_map helper methods (e.g.
murmur_hash).

Avoid disseminating every compile unit including Message.h with TransportNames and
TransportTypes and the associated unordered_map helper methods (e.g.
murmur_hash).
@coderabbitai

coderabbitai Bot commented Jan 7, 2025

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The pull request introduces a significant refactoring of transport-related definitions in the FairMQ library. A new header file TransportEnum.h is created to define the Transport enum within the fair::mq namespace. Multiple files have been updated to replace includes of Transports.h with TransportEnum.h, and several method signatures in the Channel class have been modified from inline implementations to declarations. The changes aim to improve the organization of transport-related type definitions and provide more flexible transport management capabilities.

Changes

File Change Summary
fairmq/CMakeLists.txt Added TransportEnum.h to public header files
fairmq/Channel.h - Replaced Transports.h include with TransportEnum.h
- Converted inline methods to declarations for GetTransportName(), GetTransportType(), and UpdateTransport()
fairmq/Channel.cxx Added implementations for GetTransportName(), GetTransportType(), and UpdateTransport() methods
fairmq/Device.h Replaced Transports.h include with TransportEnum.h
fairmq/Message.h - Replaced Transports.h include with TransportEnum.h
- Deprecated type aliases: fairmq_free_fn, FairMQMessage, FairMQMessagePtr
fairmq/TransportFactory.h Replaced Transports.h include with TransportEnum.h
fairmq/Transports.h Removed Transport enum definition
fairmq/UnmanagedRegion.h Replaced Transports.h include with TransportEnum.h
fairmq/shmem/Message.h Added include for Transports.h
fairmq/shmem/Segment.h Added include for Transports.h
fairmq/shmem/UnmanagedRegion.h Added include for Transports.h
fairmq/TransportEnum.h New file defining Transport enum in fair::mq namespace

Sequence Diagram

sequenceDiagram
    participant Channel
    participant TransportEnum
    
    Channel->>TransportEnum: Get Transport Type
    TransportEnum-->>Channel: Return Transport Type
    
    Channel->>TransportEnum: Update Transport
    TransportEnum->>Channel: Validate Transport
    Channel->>Channel: Invalidate Current Configuration
Loading

The sequence diagram illustrates the interaction between the Channel class and the new TransportEnum, showing how transport types can be retrieved and updated, with the channel invalidating its current configuration when a new transport is set.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
fairmq/Channel.cxx (1)

387-392: Document invalidation side effect in UpdateTransport.

The implementation is correct, but it's important to document that calling this method invalidates the channel, requiring revalidation before use.

Add a comment in the header file's method declaration:

    /// Set channel transport
    /// @param transport transport string ("default", "zeromq" or "shmem")
+   /// @note Calling this method invalidates the channel, requiring revalidation before use.
    void UpdateTransport(const std::string& transport);
fairmq/CMakeLists.txt (1)

66-66: LGTM! Consider adding documentation.

The addition of TransportEnum.h to FAIRMQ_PUBLIC_HEADER_FILES is correct and maintains proper header organization. Consider adding a comment in the CMakeLists.txt to document the purpose of this header and its relationship to transport management.

    TransportFactory.h
    Transports.h
+   # Contains core transport enumerations used across the codebase
    TransportEnum.h
    UnmanagedRegion.h
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fe95e6 and 9013ee8.

📒 Files selected for processing (13)
  • fairmq/CMakeLists.txt (1 hunks)
  • fairmq/Channel.cxx (2 hunks)
  • fairmq/Channel.h (3 hunks)
  • fairmq/Device.cxx (1 hunks)
  • fairmq/Device.h (1 hunks)
  • fairmq/Message.h (1 hunks)
  • fairmq/TransportEnum.h (1 hunks)
  • fairmq/TransportFactory.h (1 hunks)
  • fairmq/Transports.h (1 hunks)
  • fairmq/UnmanagedRegion.h (1 hunks)
  • fairmq/shmem/Message.h (1 hunks)
  • fairmq/shmem/Segment.h (1 hunks)
  • fairmq/shmem/UnmanagedRegion.h (1 hunks)
✅ Files skipped from review due to trivial changes (8)
  • fairmq/TransportEnum.h
  • fairmq/UnmanagedRegion.h
  • fairmq/Device.cxx
  • fairmq/Device.h
  • fairmq/shmem/Segment.h
  • fairmq/TransportFactory.h
  • fairmq/shmem/Message.h
  • fairmq/shmem/UnmanagedRegion.h
🔇 Additional comments (5)
fairmq/Transports.h (1)

13-13: LGTM! Changes align with PR objectives.

The relocation of the Transport enum to a separate header while keeping the static maps in this file effectively reduces unnecessary inclusions across compile units.

fairmq/Message.h (1)

13-13: LGTM! Minimizes header dependencies.

The change to include only TransportEnum.h instead of the full Transports.h reduces compile-time dependencies, as this file only needs the enum definition.

fairmq/Channel.cxx (1)

15-15: LGTM! Appropriate location for including Transports.h.

Including Transports.h here is correct as this is where the static maps are needed for the method implementations.

fairmq/Channel.h (1)

17-17: LGTM! Good separation of interface and implementation.

The changes effectively:

  1. Minimize header dependencies by including only TransportEnum.h
  2. Reduce header bloat by moving implementations to the source file

Also applies to: 148-152, 224-224

fairmq/CMakeLists.txt (1)

66-66: Verify if both transport headers are needed

While adding TransportEnum.h aligns with reducing static bloat, I notice that both Transports.h and TransportEnum.h are listed in FAIRMQ_PUBLIC_HEADER_FILES. Consider:

  1. Is Transports.h still needed as a public header?
  2. Should we deprecate Transports.h in favor of TransportEnum.h?

Let's check the usage and dependencies:

✅ Verification successful

Both transport headers serve distinct purposes and should be kept

The split between TransportEnum.h (enum definition) and Transports.h (string mappings and utilities) is well-designed and aligns with the goal of reducing bloat. Files that only need the enum can now include the minimal TransportEnum.h, while those needing the conversion utilities can include Transports.h.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if Transports.h is still being used
rg -l "Transports\.h" --type cpp

# Check what's included in both headers
echo "=== Transports.h contents ==="
cat fairmq/Transports.h || echo "File not found"
echo -e "\n=== TransportEnum.h contents ==="
cat fairmq/TransportEnum.h || echo "File not found"

Length of output: 3029

@ktf

ktf commented Jan 7, 2025

Copy link
Copy Markdown
Contributor Author

Ehm... Pardon my GenX-itude... Am I supposed to dialog / address the issues reported by coderabbit? In particular the nitpicks seems to be rather useless...

@rbx

rbx commented Jan 7, 2025

Copy link
Copy Markdown
Member

Feel free to ignore it if it's not useful.

@dennisklein dennisklein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks fine to me. Thx and a happy new year :)

@dennisklein dennisklein merged commit fe2127e into FairRootGroup:dev Jan 7, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jan 8, 2025
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.

3 participants