Skip to content

perf(bench): use NeverGrowInPlaceAllocator for stable benchmark results#184

Open
stormslowly wants to merge 2 commits intomainfrom
feat/bench-never-grow-in-place-allocator
Open

perf(bench): use NeverGrowInPlaceAllocator for stable benchmark results#184
stormslowly wants to merge 2 commits intomainfrom
feat/bench-never-grow-in-place-allocator

Conversation

@stormslowly
Copy link
Collaborator

Summary

  • Add NeverGrowInPlaceAllocator as #[global_allocator] in benchmarks to eliminate non-deterministic variance from libc::realloc in-place growth
  • Only alloc/dealloc are delegated to System; realloc falls back to the default alloc-copy-dealloc path, representing the worst-case scenario consistently

Test plan

  • cargo check --benches passes
  • Run cargo bench and verify reduced variance in results

Avoid non-deterministic in-place memory growth from `libc::realloc`
by using a custom global allocator that only delegates `alloc`/`dealloc`
to System, forcing consistent alloc-copy-dealloc behavior.
Copilot AI review requested due to automatic review settings March 26, 2026 03:47
@gemini-code-assist
Copy link

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 aims to enhance the reliability and determinism of benchmark results by standardizing memory allocation behavior. By preventing non-deterministic in-place reallocations, the changes ensure that benchmark runs consistently reflect the worst-case scenario for memory operations, leading to more stable and comparable performance metrics.

Highlights

  • Benchmark Stability: Introduced NeverGrowInPlaceAllocator as a global allocator for benchmarks to prevent non-deterministic variance caused by libc::realloc's in-place growth.
  • Memory Allocation Control: Configured the custom allocator to delegate alloc and dealloc to System, while forcing realloc to use the less efficient but consistent alloc-copy-dealloc path.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

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 custom global allocator, NeverGrowInPlaceAllocator, to benches/resolver.rs. This allocator is designed to ensure deterministic memory allocation behavior during benchmarks by forcing a copy-on-reallocate strategy, thus preventing non-deterministic in-place growth. The review suggests an improvement to remove redundant unsafe blocks within the alloc and dealloc implementations for better readability, as the functions themselves are already marked unsafe.

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 aims to make benchmark results more stable by installing a custom #[global_allocator] for the benchmark binary that prevents benefiting from non-deterministic in-place growth behavior during realloc.

Changes:

  • Add a NeverGrowInPlaceAllocator global allocator to the resolver benchmark.
  • Delegate alloc/dealloc to System while relying on the default GlobalAlloc fallback behavior for realloc.

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

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 26, 2026

Merging this PR will improve performance by 20.97%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 11 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory resolver[resolve from symlinks multi thread] 680.1 KB 562.2 KB +20.97%

Comparing feat/bench-never-grow-in-place-allocator (04d1d6d) with main (7162b33)

Open in CodSpeed

@stormslowly stormslowly requested a review from hardfist March 26, 2026 10:06
@stormslowly stormslowly enabled auto-merge (squash) March 26, 2026 10:06
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