Skip to content

Optimization: reduce len() calls in add_polynomialcoeff#3581

Merged
hwwhww merged 1 commit into
devfrom
reduce-len-call
Jan 20, 2024
Merged

Optimization: reduce len() calls in add_polynomialcoeff#3581
hwwhww merged 1 commit into
devfrom
reduce-len-call

Conversation

@hwwhww
Copy link
Copy Markdown
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 eip7594 PeerDAS label Jan 16, 2024
Copy link
Copy Markdown
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
@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

eip7594 PeerDAS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants