Skip to content

Conversation

HMegh
Copy link

@HMegh HMegh commented Jun 27, 2025

Hi,

Reducing allocations:

The Newton's iteration for gausslegendre uses only part of the information returned by the asymptotic formula asy. I moved the relevant code from asy to a new function leg_initial_guess to reduce allocations and improve performance. I have also reused the temporary vectors PP1 and PP2. This reduces allocations in rec(n) from 22 to 9.

Example 1
Current Master:

julia> @btime gausslegendre(10)
  541.186 ns (22 allocations: 1.36 KiB)

With this PR:

julia> @btime gausslegendre(10)
  396.139 ns (9 allocations: 640 bytes)

This performance improvement is less pronounced for higher values of n since the Newton iteration is O(n^2).

Example 2
Current Master:

julia> @btime gausslegendre(50)
  10.787 μs (22 allocations: 5.52 KiB)

With this PR:

julia> @btime gausslegendre(50)
  10.379 μs (9 allocations: 2.62 KiB)

CI and Aqua

Currently the tests are not passing since actions/cache@v1 is deprecated, and Aqua.jl is indicating that the packages in extras do not have a compat entry. I have upgraded the actions/cache version, and added a flag to Aqua to ignore packages in extra. All tests pass now.

Best,
Haroun

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