Skip to content

High memory use when parsing some WOFF2 fonts. #298

Open

Description

@helo-xperi

I work at Xperi. We are Chromium integrators that target embedded devices where memory is more sparse than on desktop/mobile. We've noticed that OTS can use a substantial amount of memory while parsing some large and compressed WOFF2 fonts.

We traced this down to the fact that the interface of OTSContext::Process requires holding more than two memory buffers at once while processing WOFF2 fonts, as the input buffer can't be deleted once it is no longer needed - specifically after the buffer has been decompressed. Consider this interface:

bool Process(
  OTSStream *output,
  const uint8_t *data,
  size_t length,
  uint32_t index = -1);

The input buffer, data, is both const declared and of different type than output meaning the input buffer can't be destroyed or re-used internally. This leads to a need to hold three buffers in memory simultaneously while processing compressed WOFF2 fonts.

It would be possible to make OTSContext::Process use less memory for this usecase if an additional overload was added where ownership of the input buffer could be transferred to OTSContext::Process. Something along the lines of:

ots::ExpandingMemoryStream Process(
  ots::ExpandingMemoryStream&& input, uint32_t index = -1);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions