-
Notifications
You must be signed in to change notification settings - Fork 22
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
Optionally borrow polynomial coefficients #237
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pros: - Certain functions, like evaluation, can happen without owning the coefficients, which reduces memory consumption. - Memory allocations are more visible in calling code. Cons: - Explicit lifetimes might be required more often. - Polynomial's implementations of traits `Zero` and `One` are less usable now. Should `poly.is_zero()` be unusable due to lifetime constraints (“`poly` escapes the method body”), you can use `poly.degree() < 0` instead.
Previously, the coefficient list over which a polynomial was defined was publicly accessible. Now, the coefficient list is private. A reference to it can be accessed using the new method `Polynomial::coefficients()`. This change - makes upholding internal invariants easier, and - allows changing the underlying representation without breaking downstream dependencies.
jan-ferdinand
added
the
⏭️ breaking change
Breaking change, will require an increment of the major version number. E.g: 0.3.0 -> 0.4.0
label
Oct 18, 2024
@aszepieniec, @Sword-Smith, I have requested both of you for review only because I'm not sure who this is better suited for. 😌 |
Let me know if/when you need me to run benchmarks. |
aszepieniec
approved these changes
Oct 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐮
Performance
In my eyes, this PR is ready to be merged. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
⏭️ breaking change
Breaking change, will require an increment of the major version number. E.g: 0.3.0 -> 0.4.0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor polynomials to (a) make their innards private and (b) turn their innards into a clone-on-write slice, reducing the number of allocations needed for read-only operations like polynomial evaluation.
Pros
Cons
Zero
andOne
are less usable now. Shouldpoly.is_zero()
be unusable due to lifetime constraints (“poly
escapes the method body”), you can usepoly.degree() < 0
instead.A lot of lines have changed only because of re-grouping to avoid multiple
impl
blocks with the same trait & lifetime bounds. Commit 65914d5 only makes the polynomial's innards private to simplify review.Performance
The benchmark suite indicates some improvements, some regressions, and I can't seem to identify clear patterns. I will try to make sense of the results and report back in a separate comment.
Footnotes
Methods taking
&mut self
, likescalar_mul_mut()
ornormalize()
, are unfortunate exceptions if called on aPolynomial::new_borrowed()
. I thought about making those methods consuming, and return aPolynomial<'static, FF>
, but have decided against that for now. Let me know if you disagree with that decision. ↩