Closed jan-ferdinand closed 3 weeks ago
@aszepieniec, @Sword-Smith, I have requested both of you for review only because I'm not sure who this is better suited for. :relieved:
Let me know if/when you need me to run benchmarks.
In my eyes, this PR is ready to be merged.
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 65914d5a736cce472080b12a168b4ef5d22820f 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.
[^exceptions]: 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.