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 conditional execution mem usage. #2011

Merged
merged 1 commit into from
Dec 30, 2019

Conversation

davecgh
Copy link
Member

@davecgh davecgh commented Nov 25, 2019

The existing implementation to handle conditional execution makes use of a stack to track the state of each nested conditional. It is already fairly efficient in terms of execution costs since it only considers the most recent conditional stack entry and makes use of pushing OpCondSkip to essentially track the nesting depth in unexecuted branches, however, using a stack is less efficient in terms of memory usage than is actually necessary since there is no need to use a stack at all given that all that is really needed to provide the necessary behavior is the current conditional nesting depth and the depth at which branch execution was disabled (if it has been disabled).

Given the above, this optimizes the txscript conditional execution logic by replacing the condition stack with two int32 fields to track the aforementioned cases and updates the conditional execution opcode and logic accordingly.

@davecgh davecgh added this to the 1.6.0 milestone Nov 25, 2019
@davecgh davecgh force-pushed the txscript_optimize_cond_stack branch 4 times, most recently from 31a2a9a to 49edd47 Compare November 25, 2019 18:34
Copy link
Member

@dnldd dnldd left a comment

Choose a reason for hiding this comment

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

Nicely done.

The existing implementation to handle conditional execution makes use of
a stack to track the state of each nested conditional.  It is already
fairly efficient in terms of execution costs since it only considers the
most recent conditional stack entry and makes use of pushing OpCondSkip
to essentially track the nesting depth in unexecuted branches, however,
using a stack is less efficient in terms of memory usage than is
actually necessary since there is no need to use a stack at all given
that all that is really needed to provide the necessary behavior is the
current conditional nesting depth and the depth at which branch
execution was disabled (if it has been disabled).

Given the above, this optimizes the txscript conditional execution logic
by replacing the condition stack with two int32 fields to track the
aforementioned cases and updates the conditional execution opcode and
logic accordingly.
@davecgh davecgh merged commit aad3f7c into decred:master Dec 30, 2019
@davecgh davecgh deleted the txscript_optimize_cond_stack branch December 30, 2019 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants