mattn / go-runewidth

wcwidth for golang
MIT License
608 stars 92 forks source link

Add full lookup table for single rune width. #54

Closed klauspost closed 3 years ago

klauspost commented 3 years ago

Provides nearly an order of magnitude speedup depending on how quickly the checks are done.

Data is packed at 4 bytes/rune, since the max output value is 2.

cpu: AMD Ryzen 9 3950X 16-Core Processor
BenchmarkRuneWidthAll/regular-32                  51      25539433 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidthAll/lut-32                     442       2711694 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidth768/regular-32              617528          2109 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidth768/lut-32                  605570          2038 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidthAllEastAsian/regular-32                 31      36469868 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidthAllEastAsian/lut-32                    442       2710229 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidth768EastAsian/regular-32              73273         16028 ns/op           0 B/op          0 allocs/op
BenchmarkRuneWidth768EastAsian/lut-32                 634987          1871 ns/op           0 B/op          0 allocs/op
PASS
codecov-commenter commented 3 years ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 93.56%. Comparing base (1ccc74d) to head (acbd689). Report is 26 commits behind head on master.

Files Patch % Lines
runewidth.go 72.00% 3 Missing and 4 partials :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #54 +/- ## ========================================== - Coverage 97.31% 93.56% -3.75% ========================================== Files 3 3 Lines 149 171 +22 ========================================== + Hits 145 160 +15 - Misses 3 6 +3 - Partials 1 5 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

mattn commented 3 years ago

Is the increase in memory used due to this change about 1-2MB?

mattn commented 3 years ago

Does this change behave as old if CreateLut is not called. Right?

klauspost commented 3 years ago

Is the increase in memory used due to this change about 1-2MB?

@mattn Nothing is allocated unless CreateLUT is called. Where are you observing the memory increase? Memory usage is ~500KB per "*Condition" that calls CreateLUT.

Does this change behave as old if CreateLut is not called. Right?

Correct, it is fully transparent.

mattn commented 3 years ago

Thank you