stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

bench: replace stack allocation with dynamic allocation

Open navyansh007 opened this issue 7 months ago • 3 comments

fix(math/strided/special/dfloor): replace stack allocation with dynamic allocation in benchmark

Replace fixed-size array declarations with dynamic memory allocation in the dfloor benchmark to prevent segmentation faults when processing large input sizes. The benchmark previously failed with segmentation faults for arrays with 1,000,000 elements due to stack memory limitations.

Changes:

  • Replace stack-allocated arrays with malloc/free for x and y arrays
  • Add proper error handling for memory allocation failures
  • Add memory cleanup to prevent memory leaks
  • Add error checking in main benchmark loop

Fixes: #7224

navyansh007 avatar Jun 11 '25 06:06 navyansh007

:wave: Hi there! :wave:

And thank you for opening your first pull request! We will review it shortly. :runner: :dash:

Getting Started

Next Steps

  1. A project maintainer will approve GitHub Actions workflows for your PR.
  2. All CI checks must pass before your submission can be fully reviewed.
  3. You'll need to address any failures in linting or unit tests.

Running Tests Locally

You can use make to run any of the CI commands locally from the root directory of the stdlib repository:

# Run tests for all packages in the math namespace:
make test TESTS_FILTER=".*/@stdlib/math/.*"

# Run benchmarks for a specific package:
make benchmark BENCHMARKS_FILTER=".*/@stdlib/math/base/special/sin/.*"

If you haven't heard back from us within two weeks, please ping us by tagging the "reviewers" team in a comment on this PR.

If you have any further questions while waiting for a response, please join our Gitter channel to chat with project maintainers and other community members.

We appreciate your contribution!

Documentation Links

stdlib-bot avatar Jun 11 '25 06:06 stdlib-bot

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

stdlib-bot avatar Jun 11 '25 07:06 stdlib-bot

Coverage Report

Package Statements Branches Functions Lines
math/strided/special/dfloor $\color{green}374/374$
$\color{green}+100.00\%$
$\color{green}15/15$
$\color{green}+100.00\%$
$\color{green}4/4$
$\color{green}+100.00\%$
$\color{green}374/374$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

stdlib-bot avatar Jun 11 '25 07:06 stdlib-bot

@navyansh007 Would you mind updating this PR to match the dynamic memory allocation changes in this commit: https://github.com/stdlib-js/stdlib/commit/2c9f492d8e15e860aa56f9d3b5b3845191480700? Cheers!

kgryte avatar Oct 14 '25 13:10 kgryte

Hey @kgryte, I have updated the malloc statements in the code and changed them to match the way they are written in the commit you mentioned. I request you to have a look at that. Feel free to let me know if any further changes are required.

navyansh007 avatar Oct 15 '25 04:10 navyansh007