-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor and optimize composeChar #33
Conversation
Tests are failing, need to do a bit more work before it becomes ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a stunning speed up! Great!
-- Hold an L to wait for V, hold an LV to wait for T. | ||
data JamoBuf | ||
= JamoEmpty | ||
| JamoLIndex {-# UNPACK #-} !Int | ||
= JamoLIndex {-# UNPACK #-} !Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe {-# UNPACK #-}
pragmas can be safely omitted, there is {-# OPTIONS_GHC -funbox-strict-fields #-}
anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it can be removed.
| JamoLV {-# UNPACK #-} !Char | ||
|
||
data RegBuf | ||
= RegOne !Char | ||
| RegMany !Char !Char [Char] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any invariants about which of these Char
s are combining and which are not? If yes, it is worth to reflect in comments. (Previously ReBuf
was guaranteed to consist of combining characters only, and Char
in Stater Char Rebuf
was guaranteed to be non-combining.)
You can probably put a bang before [Char]
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first one in the buffer may be a starter. Others are guaranteed to be non-starters (i.e. combining chars). I will put a comment. I will add a bang as well.
Tests are fixed now. There were two screw ups during refactoring:
Perf comparison:
|
|
|
I hope GHC would eliminate the indirection during simplification. |
Comparison with Korean can be improved relatively easily perhaps.
|
Added one more commit to speed up
|
Astonishing! |
I did not properly review the code before committing. Even though the code was wrong, the tests passed, I need to check if the tests are working properly. Unicode test suite does not have a hangul (LV, T) composition test, I had added this in an extra test suite, but it does not seem to be working. The correct code should have been:
But this does not help much, perhaps because anyway most syllables are hangul LV so we anyway have to do the expensive quotRem. I wrote this one earlier:
This gives us the following results:
Good improvement but not as dramatic. I am looking at another strategy which could be cheaper i.e. test for a jamo |
* unfold the non-decomposable case outside the recursive loop * use SPEC constr on encode
There was a lot of code bloat earlier, the core size reduced from 50K lines to 20K lines.
In composeChar: * First check the state and then make decisions based on the char type instead of doing the opposite. This simplifies the code, the core size reduces by 1/3rd (it is still huge). * With this change the code is better amenable to spec-constr optimization, with -fspec-constr-count=8 it is able to produce a tighter loop improving performance by several times (best improvement is in English benchmark).
UNPACK pragmas are redundant as we use a blanket -funbox-strict-fields
I dropped the last commit, will continue that in a separate PR and merge this. |
merged in master. |
Look at the commit messages for more details. May be a good idea to review individual commits. Here is the perf summary, before and after: