adah1972 / libunibreak

The libunibreak library
zlib License
173 stars 38 forks source link

Speed up line break prop lookup #37

Closed bbshelper closed 1 year ago

bbshelper commented 1 year ago

Hi,

I am a user of koreader (an e-reader app) which utilizes libunibreak. I noticed it spends a lot of time (10%) in libunibreak during layout and rendering. It turns out, libunibreak uses a 2-level linear lookup for line break property. For most code points, it requires like dozens of comparisons.

I've made a test change here: https://github.com/bbshelper/libunibreak/commit/aee6dbc4d2d262709af92483f619316b40cd30db. With a lookup table for BMP and binary search for higher codepoints, it is 10x faster in tests on my PC.

Would you accept this kind of change? If so, I can polish the commit and make a pull request.

adah1972 commented 1 year ago

There are too many code points for two-level look-ups now....

Yup, I think your idea is good. We need fast lookup, especially for BMP. Go ahead.