Skip to content
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

[buffer] Add flags to disable unsafe-to-concat and unsafe-to-break calculations #3454

Closed
behdad opened this issue Feb 18, 2022 · 3 comments · Fixed by #3455
Closed

[buffer] Add flags to disable unsafe-to-concat and unsafe-to-break calculations #3454

behdad opened this issue Feb 18, 2022 · 3 comments · Fixed by #3455

Comments

@behdad
Copy link
Member

behdad commented Feb 18, 2022

In my measurements, disabling those can speedup shaping by up to 17%. Vast majority of clients won't use those flags. Should have been opt-in from the beginning. Oh well. We can allow opt-out now, to allow those browsers, or Android, that don't use it to opt out and save the planet...

Note that most of that overhead is from unsafe-to-concat. unsafe-to-break is much lower-overhead. Maybe unsafe-to-concat can become opt-in?

@behdad
Copy link
Member Author

behdad commented Feb 18, 2022

unsafe-to-concat is new enough that we can still change it.

@behdad
Copy link
Member Author

behdad commented Feb 18, 2022

cc @drott @jfkthame

@behdad
Copy link
Member Author

behdad commented Feb 18, 2022

This patch is enough to regain much of the lost performance:

diff --git a/src/hb-buffer.h b/src/hb-buffer.h
index ee72dfafb..12daeba16 100644
--- a/src/hb-buffer.h
+++ b/src/hb-buffer.h
@@ -377,7 +377,8 @@ typedef enum { /*< flags >*/
   HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES   = 0x00000004u,
   HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES     = 0x00000008u,
   HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE   = 0x00000010u,
-  HB_BUFFER_FLAG_VERIFY                                = 0x00000020u
+  HB_BUFFER_FLAG_VERIFY                                = 0x00000020u,
+  HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT      = 0x00000040u
 } hb_buffer_flags_t;
 
 HB_EXTERN void
diff --git a/src/hb-buffer.hh b/src/hb-buffer.hh
index cc20f3aef..bc6992905 100644
--- a/src/hb-buffer.hh
+++ b/src/hb-buffer.hh
@@ -460,6 +460,8 @@ struct hb_buffer_t
   }
   void unsafe_to_concat (unsigned int start = 0, unsigned int end = -1)
   {
+    if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0))
+      return;
     _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT,
                      start, end,
                      true);
@@ -472,6 +474,8 @@ struct hb_buffer_t
   }
   void unsafe_to_concat_from_outbuffer (unsigned int start = 0, unsigned int end = -1)
   {
+    if (likely ((flags & HB_BUFFER_FLAG_PRODUCE_UNSAFE_TO_CONCAT) == 0))
+      return;
     _set_glyph_flags (HB_GLYPH_FLAG_UNSAFE_TO_CONCAT,
                      start, end,
                      false, true);

I suggest I put this in. As I said, unsafe-to-break seems to be much lower overhead and also water-under-the-bridge already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant