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

secp256k1: Reduce scalar base mult copies. #2898

Merged
merged 1 commit into from
Mar 18, 2022

Commits on Mar 18, 2022

  1. secp256k1: Reduce scalar base mult copies.

    Profiling shows that around 7.5% of the time in scalar base
    multiplication is attributed to duffcopy.  Upon further examination,
    this is the result of a combination of the range statement making copies
    of the bytes and the need to construct a Jacobian point from the
    individual field values stored in the in-memory byte points table.
    
    This optimizes the function to avoid that as follows:
    
    - Perform the conversion to Jacobian once when the affine byte table is
      decompressed from the stored values
    - Make use of those Jacobian points directly
    - Use an indexed for loop instead of a range over the bytes
    - Perform the calculation using the result variable directly instead of
      via a local variable that is copied to the result
    
    The following benchmark results show the speedup is in line with the
    expected gains per the profiling results:
    
    name                     old time/op   new time/op    delta
    ------------------------------------------------------------------------------
    ScalarBaseMultNonConst   24.1µs ±22%   22.5µs ± 2%   -6.97%  (p=0.000 n=98+96)
    davecgh committed Mar 18, 2022
    Configuration menu
    Copy the full SHA
    aae0128 View commit details
    Browse the repository at this point in the history