Repository navigation
Add a fast path for shaping ASCII text - #11273
Conversation
|
r? @pcwalton |
| let value = BigEndian::read_i16(&pairs[i * KERN_PAIR_LEN + 4..]); | ||
| trace!("Kerning for {}/{}: {:?}", first_glyph, second_glyph, value); | ||
| return value as f64 * table.scale; | ||
| } |
There was a problem hiding this comment.
Can this use Vec::binary_search()?
Even if not, I still think I'd rather have this be a separate function.
|
New code was committed to pull request. |
| handle: fctx.clone(), | ||
| can_do_fast_kerning: false, | ||
| }; | ||
| handle.can_do_fast_kerning = handle.has_table(KERN) || !handle.has_table(GPOS); |
There was a problem hiding this comment.
Hmm. I would expect handle.has_table(KERN) && !handle.has_table(GPOS). Am I missing something?
There was a problem hiding this comment.
Switched to has_table(KERN) && !has_table(GPOS) for now.
|
New code was committed to pull request. |
|
Addressed review comments.
I assumed that if a font has both 'kern' and 'GPOS', then falling back to the 'kern' table would be sufficient for shaping ASCII-only strings. It would be more conservative to use the slow path in this case, however. This affects some commonly-used fonts like ArialMT and TimesNewRoman on Mac OS, and the DejaVu fonts on Linux. Even if we implement partial GPOS support in the fast path, we'll need to make a similar assumption that ASCII characters aren't affected by any unsupported GPOS features (or, somehow scan the whole table to verify this). We could also make this depend on the |
|
@mbrubeck I was actually assuming we'd scan the table to verify this. I looked at the tables in FontForge and they seemed to pass the test from first glance. But this can be a followup. |
|
New code was committed to pull request. |
|
New code was committed to pull request. |
|
New code was committed to pull request. |
|
New code was committed to pull request. |
| } | ||
| let num_subtables = BigEndian::read_u16(&table[2..]); | ||
| let mut start = 4; | ||
| for _ in 0..num_subtables { |
There was a problem hiding this comment.
Kinda weird that the spec doesn't say what the subtable version number is supposed to be. Maybe add a TODO to perhaps check this in the future?
|
Looks good, just had a couple of nits! |
|
New code was committed to pull request. |
|
@bors-servo r=pcwalton
|
|
📌 Commit 5991afa has been approved by |
Add a fast path for shaping ASCII text On both my Linux laptop and iMac, this is about twice as fast as Harfbuzz text shaping on https://en.wikipedia.org/wiki/Barack_Obama. I haven't tested this on any high-DPI (retina) displays, and I'm not 100% certain that the font unit scaling is correct there. Depends on servo/core-text-rs#50. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11273) <!-- Reviewable:end -->
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel, mac-dev-unit, mac-rel-css, mac-rel-wpt, windows |
|
I think this is going backwards, Geko does not have a fast path and Blink is killing its fast path as well because it is proven to be a bad idea on the long run. HarfBuzz should be pretty fast when no OpenType layout is involved anyway, so if the code is slow then this is probably an issue in the Servo side. CC @behdad. |
|
The fast path in WebKit doesn't do kerning at all from what I can tell. That's why it's being removed. But our fast path is different. By design, our fast path only kicks in when we detect that there will be no quality difference between HarfBuzz and what we do. It's been shown to result in a 2x speedup, and I don't see anything wrong that we're doing in Servo that would cause HB to be slow. Additionally, we have potential vectorization opportunities, so we may well pull further ahead of HB with this fast path in the long run. |
|
I don’t know Rust that well, but the code seems to do the fast path when the font has a Also if HarfBuzz path in Servo is slow, I think making it faster benefits everyone not only user of ASCII text and fonts with no OpenType layout table. Both Gecko and Blink cache the shaping result in various way to speed things up. |
|
This is still an experiment; it remains to be seen whether it will still be faster than HarfBuzz on typical fonts once it supports ligatures and other OpenType features. Perhaps it won't be. If we do find any significant wins, I'll definitely see if they they can be shared with HarfBuzz. Part of the speedup here may be from better inlining. (We might also be able to get this from Harfbuzz by compiling it with Clang and using cross-language LTO, which is also something we plan to pursue.) Part of it is also from writing data directly into Servo's internal data structures without allocating any intermediate buffers. And having a separate path for ASCII inside of Servo might be a win whether or not it uses HarfBuzz.
Yeah, we ought to disable the fast path if any ASCII character is covered by a table that it doesn't support. I'm working on this. |
|
This is so not what we expect HarfBuzz clients to be doing... My 0.02USD. |
For years, Servo has had a rudimentary shaper that read the `kern` tables and tried to do a very basic version of shaping itself. This change removes that shaper and all associated code because: 1. It was rarely used: the fast shaper only ran on LTR ASCII text for fonts with neither `GSUB` nor `GPOS` tables. That covers a very small number of situations. 2. It isn't really faster: My measurements showed that even when bending over backwards to use the fast shaper the difference in performance was within noise or slower on both macOS and Linux. HarfBuzz is a lot faster nowadays and we do a lot more caching. 3. It produces inaccurate results. My testing showed that the fast shaper can produce degraded shaping results in certain conditions. 4. It added a lot of code complexity and was always considered to be a bad idea. For example see this comment: <servo#11273 (comment)>. There are interesting optimizations to shaping coming, so we should finally retire this workaround for a real shaper. Signed-off-by: Martin Robinson <[email protected]>
For years, Servo has had a rudimentary shaper that read the `kern` tables and tried to do a very basic version of shaping itself. This change removes that shaper and all associated code because: 1. It was rarely used: the fast shaper only ran on LTR ASCII text for fonts with neither `GSUB` nor `GPOS` tables. That covers a very small number of situations. 2. It isn't really faster: My measurements showed that even when bending over backwards to use the fast shaper the difference in performance was within noise or slower on both macOS and Linux. HarfBuzz is a lot faster nowadays and we do a lot more caching. 3. It produces inaccurate results. My testing showed that the fast shaper can produce degraded shaping results in certain conditions. 4. It added a lot of code complexity and was always considered to be a bad idea. For example see this comment: <servo#11273 (comment)>. There are interesting optimizations to shaping coming, so we should finally retire this workaround for a real shaper. Testing: This should have a very tiny change in behavior, which is unlikely to be reflected in test results. There isn't a good way to test removal of this obsolete fast path. Signed-off-by: Martin Robinson <[email protected]>
For years, Servo has had a rudimentary shaper that read the `kern` tables and tried to do a very basic version of shaping itself. This change removes that shaper and all associated code because: 1. It was rarely used: the fast shaper only ran on LTR ASCII text for fonts with neither `GSUB` nor `GPOS` tables. That covers a very small number of situations. 2. It isn't really faster: My measurements showed that even when bending over backwards to use the fast shaper the difference in performance was within noise or slower on both macOS and Linux. HarfBuzz is a lot faster nowadays and we do a lot more caching. 3. It produces inaccurate results. My testing showed that the fast shaper can produce degraded shaping results in certain conditions. 4. It added a lot of code complexity and was always considered to be a bad idea. For example see this comment: <servo#11273 (comment)>. There are interesting optimizations to shaping coming, so we should finally retire this workaround for a real shaper. Testing: This should have a very tiny change in behavior, which is unlikely to be reflected in test results. There isn't a good way to test removal of this obsolete fast path. Signed-off-by: Martin Robinson <[email protected]>
On both my Linux laptop and iMac, this is about twice as fast as Harfbuzz text shaping on https://en.wikipedia.org/wiki/Barack_Obama.
I haven't tested this on any high-DPI (retina) displays, and I'm not 100% certain that the font unit scaling is correct there.
Depends on servo/core-text-rs#50.
This change is