-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize binary decoding of builtins (#1810)
* 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: s <- decodeString let len_s = length s if len_s == length "Natural/build" && sameBytes s "Natural/build" then return NaturalBuild else if len_s == length "Natural/fold" && sameBytes s "Natural/fold" ... Decoding `Sort`, the most extreme case, would involve a total of 32 conditional 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. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c43bfd2
commit 93313dc
Showing
1 changed file
with
76 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters