Skip to content

Conversation

@mjp41
Copy link
Member

@mjp41 mjp41 commented Jul 9, 2025

This PR adds some inlining attributes to lambdas on the fast path. Some versions of g++ and clang++ were not inlining as much as expected, and leading to poor codegen. This PR fixes that.

Additionally, it disables the fork prevention during remote allocator posting. This was visible in some traces as causing a bottleneck.

mjp41 added 3 commits July 8, 2025 11:06
This commit adds some inlining requirements on lambda functions
used on the fast path for the allocations path.  This improves the
g++ code generation by preventing the stack allocation of the lambda
which is then not optimised away.
@mjp41 mjp41 requested a review from Copilot July 9, 2025 13:53
Copy link
Contributor

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 adds SNMALLOC_FAST_PATH_LAMBDA to various lambdas to encourage inlining on critical paths and comments out fork-prevention logic to remove a performance bottleneck during remote allocator posting.

  • Annotated several lambda definitions with the SNMALLOC_FAST_PATH_LAMBDA attribute.
  • Disabled the PreventFork guard in freelist_queue.h and expanded the comment explaining why.
  • Updated comments to describe alternative post-fork handling without enabling the fork-prevention code.

Reviewed Changes

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

File Description
src/snmalloc/mem/remotecache.h Added SNMALLOC_FAST_PATH_LAMBDA to a forwarding lambda for inlining.
src/snmalloc/mem/freelist_queue.h Commented out PreventFork usage and expanded explanatory comments.
src/snmalloc/mem/corealloc.h Annotated multiple lambdas with SNMALLOC_FAST_PATH_LAMBDA for inlining.

// // with the following code, but it is not currently enabled as it
// // has negative performance impact.
// // An alternative would be to reset the queue on the child postfork
// // handler to ensure that the queue has not be blackholed.
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

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

Fix grammar: change 'has not be blackholed' to 'has not been blackholed'.

Suggested change
// // handler to ensure that the queue has not be blackholed.
// // handler to ensure that the queue has not been blackholed.

Copilot uses AI. Check for mistakes.
@mjp41
Copy link
Member Author

mjp41 commented Jul 9, 2025

This was running on an Azure Linux 3 instance with clang++ (18.1.8) and g++ (13.2.0)
image

@mjp41 mjp41 merged commit b49a42d into microsoft:main Jul 9, 2025
79 checks passed
@mjp41 mjp41 deleted the gcc_cq branch July 9, 2025 14:29
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.

2 participants