-
Notifications
You must be signed in to change notification settings - Fork 117
Code Quality - inlining #792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
There was a problem hiding this 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_LAMBDAattribute. - Disabled the
PreventForkguard infreelist_queue.hand 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. |
src/snmalloc/mem/freelist_queue.h
Outdated
| // // 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. |
Copilot
AI
Jul 9, 2025
There was a problem hiding this comment.
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'.
| // // handler to ensure that the queue has not be blackholed. | |
| // // handler to ensure that the queue has not been blackholed. |

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.