-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optimistic text parsing for 20% improvement
In the same vein of data driven optimizations: #111, #112 This commit introduces a fast, happy path parsing routine that takes advantage of how typical save files are laid out and how the text deserializer essentially only calls `read` when it either needs a key or a value. Keys will have leading whitespace (newline followed by tabs), so we consume up to 8 of them at once. For EU4 this covers 100% of keys in about 95% of saves (ie: it is extremely rare for there to be more than 8 whitespace characters in a row). This happy path hoists the the common keys and values (`{`, `}`, `"`, and alphanumeric+dash) so it's more obvious to the compiler and CPU what we're looking for. After all these years, I still can't derive a good function to identify a boundary character within 8 bytes, but I think I found the next best thing: loop unrolling. Speaking of boundary characters, I removed the notion of character classes as they were unused. The happy path for parsing quoted data will now process 8 bytes at once and will ask for forgiveness if an escape character is encountered. The 20% improvement comes from measuring eu4 save deserialization, so the improvement to this individual function is much greater.
- Loading branch information
1 parent
ebe4999
commit 2223ea3
Showing
3 changed files
with
129 additions
and
38 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
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
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