Performance and optimization improvements, changes to encoding #184
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.
This pr replaces encoding.js with a more optimized version which works with a wasm module (or arraybuffer). Some formats were changed to accomodate this, e.g.: immediates are no longer encoded, e.g.
[ Opcodes.i32_const, ...signedLEB128(x) ]
->[ Opcodes.i32_const, x ]
which makes a lot of reading much more straightforward, the entire opcode is always in the first index, e.g.Opcodes.i32_trunc_sat_f64_s
->[ Opcodes.i32_trunc_sat_f64_s ]
. Additionally, the backtrace system has been reworked to use binary search to find the correct instruction instead of searching everything. Because of the previous two changes, a lot of other code needed to be reworked in order to fit the new scheme. Also: block types in Porffor.wasm are now encoded as their name instead of their id and multi-value block types are also supported (e.g.[ Opcodes.if, [ [ Valtype.f64, Valtype.i32 ], [ Valtype.i32 ] ] ]
which is encodedif f64 i32 -> i32
in Porffor.wasm). Because it bothered me there is also now a more proper way of doing constant evaluation with opt.js (giant table jumpscare) and optimizations relating to drop have been generalized (oh wow this so much more involved than before). (yeah I couldn't resist adding optimizations)