perf(bench): use NeverGrowInPlaceAllocator for stable benchmark results#184
perf(bench): use NeverGrowInPlaceAllocator for stable benchmark results#184stormslowly wants to merge 2 commits intomainfrom
Conversation
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.
Summary of ChangesHello, 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
🧠 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 AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
NeverGrowInPlaceAllocatorglobal allocator to the resolver benchmark. - Delegate
alloc/dealloctoSystemwhile relying on the defaultGlobalAllocfallback behavior forrealloc.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Merging this PR will improve performance by 20.97%
|
| 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)
Summary
NeverGrowInPlaceAllocatoras#[global_allocator]in benchmarks to eliminate non-deterministic variance fromlibc::reallocin-place growthalloc/deallocare delegated toSystem;reallocfalls back to the default alloc-copy-dealloc path, representing the worst-case scenario consistentlyTest plan
cargo check --benchespassescargo benchand verify reduced variance in results