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

txscript: optimize IsUnspendable by removing all allocations #1375

Closed
wants to merge 1 commit into from

Conversation

Roasbeef
Copy link
Member

During my work to optimize the IBD of btcd, I've been profiling heavily.
I've noticed that this call IsUnspendable shows up in several hot
spots during block validation, as we need to know if we should add a
UTXO to the view/cache, etc. The current version uses parseScript to
parse out all the pops and such. This is nice when we want to be able to
easily manipulate things like data pushes, but for this simple check,
it's unnecessary. The new version simply makes checks against the raw
script which saves us a ton of allocations and CPU cycles.

During my work to optimize the IBD of btcd, I've been profiling heavily.
I've noticed that this call `IsUnspendable` shows up in several hot
spots during block validation, as we need to know if we should add a
UTXO to the view/cache, etc. The current version uses `parseScript` to
parse out all the pops and such. This is nice when we want to be able to
easily manipulate things like data pushes, but for this simple check,
it's unnecessary. The new version simply makes checks against the raw
script which saves us a ton of allocations and CPU cycles.
@davecgh
Copy link
Member

davecgh commented Jan 29, 2019

While I completely agree with the concept of this PR (in fact I'd ultimately like to see much less parsing of the scripts into pops in general), this is a change to the semantics and would result in entries that can't be parsed being admitted to the utxo set. Any attempts to spend them would fail, so it shouldn't be a problem from a standpoint of consensus, but still not entirely desirable.

Perhaps it would make sense to add an IsParsable function which essentially does what parseScriptTemplate does, but rather than performing any allocations for the opcodes and data, it merely scans the script in the same way and errors.

I believe a function like that would be useful for more than just this.

@jakesylvestre
Copy link
Collaborator

@jcvernaleo (as per #1530)

  • Low priority
  • Outdated

@Roasbeef
Copy link
Member Author

No longer needed anymore due to #1769

@Roasbeef Roasbeef closed this Nov 17, 2021
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.

None yet

4 participants