WIP: Optimize exe size #176
Open
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.
Making this PR to see if it reduces the execution time of dash and zsh, it may or may not be merged.
Context
On certain shells, scripts slow down the more variables there are in the environment. This is generally caused by the data structure storing the environment not being adapted to contain this many variables (i.e. dash's 37 entry hash table), and can make the execution time quadratic even when algorithms are linear, as each variable lookup takes a linear time. This means small memory reductions can significantly reduce execution time, as demonstrated in #77.
This PR optimizes the instruction encoding to use more compact encoding of common instructions:
This PR doesn't touch the exe code generator, where a lot more optimizations are possible but would increase code complexity.
Results
Methodology:
Other possible memory optimizations
The
codebuffer stores bytes of machine code but hasint[]as its type. Using the full 32 bits of ints could cut by 4 the number of environment variables used to store machine code, but labels rely on the extra space to store metadata that's used to resolve addresses that are not yet known.