Skip to content

Only write explicit tuple min/maxes if there is an intermediate tent #1345

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

Merged
merged 8 commits into from
Feb 13, 2025

Conversation

Hoolean
Copy link
Contributor

@Hoolean Hoolean commented Feb 6, 2025

Moved from original implementation in googlefonts/fontc#1225.

Motivation for moving:

I've hit a road block adding tests: fontations' GlyphDeltas is public but its fields are not, and so intermediate_region cannot be inspected after construction.

We could make this field public, but I am tempted to argue that we make the wider change of moving the abstraction boundary lower into fontations, and treat this as serialisation logic.

e.g. give GlyphDeltas a Vec<(F2Dot14, F2Dot14, F2Dot14)> (or custom struct equivalent) and determine whether explicit intermediate coordinates are needed to be written at serialisation time.

I think this optimisation is higher-level than delta set optimisation but lower-level than IUP optimisation -- it is lossless, ttx does not expose it, and there has never been motivation to toggle it -- and so it may be more ergonomic there. We could avoid unzipping until serialisation time, ditch the assert that the tuple lengths are the same, and gain a bit more immutability for example.


This PR roughly sketches how the optimisation could look in a new home here instead. In general I think it has reduced the complexity of the code in the original PR, at the cost of some additional Vecs that could be targeted later if we end up in the hot path, and some boilerplate when we already know we do not have intermediate regions in the test cases.

If we are happy with this direction then we can polish the types and tidy the PR, and I will look to furnish it with unit tests too.

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good direction, would be happy to get this in after a bit of polish.

Hoolean and others added 5 commits February 11, 2025 17:35
Moved from original implementation in googlefonts/fontc#1225, see
discussion.

This optimisation is also implemented in fontTools, and reduced `gvar`
table size by ~50% when testing locally on a large variable font.
Unfortunately we lose some of the simplicity of the prior approach, as
there is no Option `collect()` for `any()`, and we need to make the
implied intermediates available outside of the coordinates struct.
@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 11, 2025

I've now added an upstream fontc PR to follow the new API, and unit tests for the new logic; we'll probably want to feed a font all the way through a ttx-diff pipeline before merging

@Hoolean Hoolean marked this pull request as ready for review February 11, 2025 19:19
@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 11, 2025

We should be good to undraft here - ready for review!

Hoolean and others added 2 commits February 11, 2025 19:21
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really have any complaints about this now then, can I? @Hoolean I'm happy to merge unless you are aware of any blockers.

@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 12, 2025

I'll do a ttx_diff run-through of a large font through the whole shebang (googlefonts/fontc#1253) just to check we're still capturing everything, but after that I'm confident we're ready to go :)

@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 12, 2025

Identical 💪 Let's merge!

Comment on lines +337 to +338
peak: F2Dot14,
min: F2Dot14,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is probably just cosmetic, as this isn't really a tuple but a struct with named fields, but I'm used to seeing a "tent" as a { min, peak, max } in this particular order, where peak is between min and max, by definition. I wonder if we should reoder.
Also about min/max.. I believe the spec prefers to call them start and end respectively, though the meaning is clear anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're using min/max elsewhere, so I'm happy to just keep it consistent. ordering is an internal detail so we can change that later, I think it makes sense to get this merged. :)

@cmyr cmyr merged commit 2963bf8 into googlefonts:main Feb 13, 2025
8 checks passed
@RickyDaMa RickyDaMa deleted the conditional-gvar-intermediates branch February 13, 2025 10:06
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 this pull request may close these issues.

4 participants