Skip to content

fix(minor): malloc counter regression#351

Merged
supersonicbyte merged 1 commit intomainfrom
fix/malloc-regression
Mar 3, 2026
Merged

fix(minor): malloc counter regression#351
supersonicbyte merged 1 commit intomainfrom
fix/malloc-regression

Conversation

@supersonicbyte
Copy link
Copy Markdown
Contributor

Description

With PR #347 we added trait support and we changed the #canImport(jemalloc) to #if Jemalloc. Since the older toolchains will execute the Package@5.9 and in there we do not have a way to enable the trait the code guarded with the #if will never compile, the #else block will execute and we will get the stub implementation of the malloc counter which return 0.

Quick fix is to revert back to use #canImport.

Related issue: #350

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Minimal checklist:

  • I have performed a self-review of my own code
  • I have added DocC code-level documentation for any public interfaces exported by the package
  • I have added unit and/or integration tests that prove my fix is effective or that my feature works

@supersonicbyte supersonicbyte requested a review from hassila March 3, 2026 12:00
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 resolves a regression in the Benchmark package's malloc counter functionality. A previous change introduced an issue where older Swift toolchains, lacking trait support, would bypass the jemalloc integration and instead use a non-functional stub, resulting in incorrect memory allocation reporting. The fix involves reverting a conditional compilation directive to canImport(jemalloc), thereby restoring proper jemalloc detection and accurate malloc statistics across all supported toolchains.

Highlights

  • Malloc Counter Regression Fix: Reverted the conditional compilation directive from #if Jemalloc to #if canImport(jemalloc) in the MallocStatsProducer+jemalloc.swift file. This change addresses a regression where older toolchains would incorrectly use a stub malloc counter, leading to inaccurate memory allocation statistics.
  • Toolchain Compatibility: Ensured compatibility with older Swift toolchains by restoring the canImport check, which correctly identifies the availability of the jemalloc module, preventing the fallback to a zero-returning malloc counter.
Changelog
  • Sources/Benchmark/MallocStats/MallocStatsProducer+jemalloc.swift
    • Reverted conditional compilation from #if Jemalloc to #if canImport(jemalloc) to correctly enable jemalloc integration.
  • Tests/BenchmarkTests/OperatingSystemAndMallocTests.swift
    • Updated the conditional compilation directive in testMallocProducerLeaks from #if Jemalloc to #if canImport(jemalloc) to align with the fix.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
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

The changes in this pull request revert the conditional compilation checks for jemalloc from using a SwiftPM trait (#if Jemalloc) back to using #if canImport(jemalloc). This addresses a regression on older toolchains as described in the pull request description. The changes are applied consistently across the application logic and the corresponding tests, and appear to be a correct fix for the issue.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

@supersonicbyte supersonicbyte merged commit 69bde19 into main Mar 3, 2026
14 of 16 checks passed
@supersonicbyte supersonicbyte deleted the fix/malloc-regression branch March 3, 2026 12:12
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