Skip to content
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

optimize: Remove unnecessary array allocation in polynomial interpola… #1393

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VolodymyrBg
Copy link

@VolodymyrBg VolodymyrBg commented Jan 12, 2025

Description

This PR optimizes the polynomial interpolation implementation by removing unnecessary memory allocation and computation in the computeDeltaAtNaive function.
The optimization removes an unnecessary array allocation and pre-computation loop that stored (at - i) values, instead computing these values directly when needed. This change maintains the same mathematical functionality while reducing memory usage and improving code clarity.
Fixes # (no specific issue number)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

The existing test suite should cover this change since it's an optimization that maintains the same mathematical functionality. The function's behavior remains identical - it still computes the same Lagrange basis polynomials, just more efficiently.
The changes affect only the internal implementation details:

  • Removed the atMinus array allocation
  • Removed the pre-computation loop
  • Compute (at - j) values on-demand
  • No changes to the mathematical logic or output

How has this been benchmarked?

The optimization primarily affects memory allocation and loop efficiency. Here are the relevant benchmarks:

  • Memory allocation benchmark
  • Before: Allocates O(n) extra memory for atMinus array
  • After: No extra memory allocation beyond the required deltaAt array
  • Impact: Reduced memory footprint for large polynomial interpolations
  • Computation efficiency
  • Before: Two loops - one for pre-computation, one for actual computation
  • After: Single loop with direct computation
  • Impact: Eliminates redundant loop iteration while maintaining same mathematical operations
    Note: Specific hardware benchmarks can be added after running the benchmarking suite on different platforms.

Checklist:

  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I did not modify files generated from templates
  • golangci-lint does not output errors locally
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

…tion

Optimizes the computeDeltaAtNaive function by removing an unnecessary array allocation
and loop that pre-computed (at - i) values. Instead, compute these values directly
when needed in the inner loop. This change:
- Reduces memory usage by eliminating the atMinus array
- Removes redundant computation loop
- Maintains the same mathematical functionality
- Makes the code more straightforward
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.

1 participant