Optimize binary decoding of builtins #1810
Merged
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.
Use decodeUtf8ByteArray to avoid UTF16-encoding the scrutinee.
Optimize the pattern matching by grouping the patterns by length.
GHC currently doesn't produce static length information for string
literals. Consequently the pattern matching worked somewhat like this:
Decoding
Sort
, the most extreme case, would involve a total of 32conditional jumps as a consequence of length comparisons alone.
Judging by the Core, we can get that number down to 8 by grouping
the patterns by length: One to check the length of the decoded string,
and (unfortunately) still one each for the 7 candidate literals of
length 4.
The number of string content comparisons should be unchanged.
The result of these optimizations is that the time to decode the cache for cpkg
is reduced by 7-9%. Decoding time for the Prelude goes down by 13-16%.
This also changes the builtin encoding to use encodeUtf8ByteArray in order
to avoid UTF16-encoding and decoding the builtins strings. I didn't check
the performance implications though.
Context: #1804.