Skip to content

txscript: Reduce checkmultisig allocs.#2890

Merged
davecgh merged 1 commit intodecred:masterfrom
davecgh:txscript_reduce_checkmultisig_allocs
Mar 17, 2022
Merged

txscript: Reduce checkmultisig allocs.#2890
davecgh merged 1 commit intodecred:masterfrom
davecgh:txscript_reduce_checkmultisig_allocs

Conversation

@davecgh
Copy link
Copy Markdown
Member

@davecgh davecgh commented Mar 4, 2022

Profiling allocations during an initial chain sync shows that a large portion of the allocations due to the CHECKMULTISIG opcode are the result of generating the list of public keys and signatures.

This eliminates those allocations as follows:

  • Use slices into fixed-size stack-based backing arrays for the typical number of public keys and signatures
  • Make the slice of signature info contiguous instead of pointers which not only eliminates the associated allocations, but also provides better cache locality

@davecgh davecgh added this to the 1.8.0 milestone Mar 4, 2022
@davecgh davecgh force-pushed the txscript_reduce_checkmultisig_allocs branch from 40583b0 to 67c54d3 Compare March 4, 2022 03:15
@davecgh davecgh force-pushed the txscript_reduce_checkmultisig_allocs branch from 67c54d3 to 2b97fc8 Compare March 10, 2022 17:08
Comment thread txscript/opcode.go Outdated
@davecgh davecgh force-pushed the txscript_reduce_checkmultisig_allocs branch from 2b97fc8 to d18fe80 Compare March 11, 2022 18:18
Comment thread txscript/opcode.go
var pubKeys [][]byte
if numPubKeys <= numPubKeysHint {
var pubKeysArr [numPubKeysHint][]byte
pubKeys = pubKeysArr[0:0:numPubKeys]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had forgotten this syntax to set the capacity from an existing array. Just confirming: https://go.dev/play/p/rW_AkOcMhSg

Profiling allocations during an initial chain sync shows that a large
portion of the allocations due to the CHECKMULTISIG opcode are the
result of generating the list of public keys and signatures.

This eliminates those allocations as follows:

- Use slices into fixed-size stack-based backing arrays for the typical
  number of public keys and signatures
- Make the slice of signature info contiguous instead of pointers which
  not only eliminates the associated allocations, but also provides
  better cache locality
@davecgh davecgh force-pushed the txscript_reduce_checkmultisig_allocs branch from d18fe80 to bf841fe Compare March 17, 2022 10:23
@davecgh davecgh merged commit bf841fe into decred:master Mar 17, 2022
@davecgh davecgh deleted the txscript_reduce_checkmultisig_allocs branch March 17, 2022 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants