MathInterpreter: Replace Instruction polymorphism with bytecode #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Antonin,
I hope you're keeping well.
This change replaces the
Instruction
class hierarchy with a bytecode-based instruction representation. Instead of anInstruction
instance, each instruction opcode is specified by a single byte, and instruction arguments are packed into the bytecode array. The arithmetic operations are represented by a single byte, the load, store and call operations are encoded as a byte followed by the variable or function address, and the constant instruction is encoded as a single opcode followed by the double-precision floating point value. I hope this makes sense. If not, this should provide a fuller explanation.Replacing the polymorphic instruction classes with a packed bytecode array increases the locality of reference during execution. After some rough benchmarks I found the improvement was a factor of two, though more performance could be squeezed out through other modifications. For example, the
std::deque
container wrapped by thestd::stack
could be replaced with astd::vector
.Let me know what you think.
Best,
Matt