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

Optimization: reduce len() calls in add_polynomialcoeff #3581

Merged
merged 1 commit into from
Jan 20, 2024
Merged

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Jan 16, 2024

Description

I made some profiles on the DAS test case test_verify_cell_proof, which includes a compute_cells_and_proofs call and two verify_cell_proof calls. It turns out len() is somewhat expensive if we call it 400M times.

For the sake of tidiness and readability, We intentionally didn't have such optimization in spec writing. However, this one seems gain great performance improvement with only two extra lines.

Before

  • Speed: in 356.67s (0:05:56)

After reducing the len() calls in add_polynomialcoeff

This minor optimization here use temporary variables to keep the len(a) and len(b) results:

def add_polynomialcoeff(a: PolynomialCoeff, b: PolynomialCoeff) -> PolynomialCoeff:
    """
    Sum the coefficient form polynomials ``a`` and ``b``.
    """
    a, b = (a, b) if len(a) >= len(b) else (b, a)
    length_a = len(a)
    length_b = len(b)
    return [(a[i] + (b[i] if i < length_b else 0)) % BLS_MODULUS for i in range(length_a)]

  • Speed: in 234.21s (0:03:54)

It reduced ~35% time of this case.

@hwwhww hwwhww added the EIP-7594 PeerDAS label Jan 16, 2024
Copy link
Contributor

@asn-d6 asn-d6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hwwhww hwwhww merged commit f1dff5f into dev Jan 20, 2024
30 checks passed
@hwwhww hwwhww deleted the reduce-len-call branch January 20, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EIP-7594 PeerDAS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants