txscript: Reduce script parse opcode allocs. (#677)

This changes the script template parsing function to use a pointer into
the constant global opcode array for parsed opcodes as opposed to making
a copy of the opcode entries which causes unnecessary allocations.

Profiling showed that after roughly 48 hours of operation, this
copy was the culprit of 207 million unnecessary allocations.
This commit is contained in:
Dave Collins 2016-04-25 16:17:07 -05:00
parent b87723cd94
commit 644570487f

View file

@ -105,8 +105,8 @@ func parseScriptTemplate(script []byte, opcodes *[256]opcode) ([]parsedOpcode, e
retScript := make([]parsedOpcode, 0, len(script))
for i := 0; i < len(script); {
instr := script[i]
op := opcodes[instr]
pop := parsedOpcode{opcode: &op}
op := &opcodes[instr]
pop := parsedOpcode{opcode: op}
// Parse data out of instruction.
switch {