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

Only write explicit tuple mins/maxes if there is an intermediate tent #1225

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Hoolean
Copy link
Contributor

@Hoolean Hoolean commented Jan 30, 2025

This is a lossless optimisation that is also implemented in fontTools, and reduced gvar table size by ~50% when testing locally on a large variable font.

I inlined TupleBuilder as there was a precise ordering needed for converting the types, comparing values, and making the output conditional that was tricky to represent in the existing abstraction without lots of zipping and unzipping.

I tried a few functional patterns but couldn't find anything elegant without wider changes to types owing to the previous ordering, so thought it would be better to leave it inline and imperative and reach out for feedback first before doing anything more opinionated 😄

Before merging, this new logic would benefit greatly from unit test coverage too.

This optimisation is also implemented in fontTools, and reduced `gvar`
table size by ~50% when testing locally on a large variable font.
@Hoolean
Copy link
Contributor Author

Hoolean commented Jan 30, 2025

(clippy lints are valid, the trace!(...) should make a comeback before we merge, and the explicit return is left behind from when I was still chopping and changing things)

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.

Looks good! I think it would be possible to continue using the builder if we wanted, and change it so that build() returns (Tuple, Option<(Tuple, Tuple)>) but I also think it's fine inlined since it isn't used anywhere else.

I wouldn't worry about putting back the trace!, and I'll be happy to merge when CI is green.

fontbe/src/orchestration.rs Outdated Show resolved Hide resolved
let mut peaks = Vec::<F2Dot14>::new();
let mut maxes = Vec::<F2Dot14>::new();

// Optimisation: only write explicit mins and maxes if at least one of the tents is
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to add test(s) to prove it works?

@Hoolean
Copy link
Contributor Author

Hoolean commented Jan 31, 2025

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 treating 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.

Am happy to go either way; interested to hear your thoughts :)

@anthrotype
Copy link
Member

I am tempted to argue that we make the wider change of moving the abstraction boundary lower into fontations

I also think this logic belongs to fontations

@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 3, 2025

I'll put together a PR there to see how this looks

Hoolean added a commit to daltonmaag/fontations that referenced this pull request Feb 6, 2025
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.
Hoolean added a commit to daltonmaag/fontations that referenced this pull request Feb 6, 2025
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.
@Hoolean
Copy link
Contributor Author

Hoolean commented Feb 6, 2025

Moved to googlefonts/fontations#1345

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