linebender / norad

Rust crate for working with Unified Font Object files
Apache License 2.0
43 stars 12 forks source link

reuse storage when parsing multiple glyphs #221

Open cmyr opened 2 years ago

cmyr commented 2 years ago

just noticed this, but currently during parsing we allocate storage for each individual glyph that we parse. It would not be that hard to reuse a single allocation between parsings.

Ultimately this will not be a big win and we shouldn't lose too much sleep over it, but also it should be fairly easy and it shouldn't require breaking changes (at the very least we can just add API to do this internally when we're loading layers.)

One complication is how to share buffers between parsers across threads when we're loading in parallel. 🤔

madig commented 2 years ago

I like. Buffer per thread?

cmyr commented 2 years ago

yea, something like this. I'm not sure how best to do this with rayon, though..

edit: looks possible, there are some tools for building custom threadpools with thread-local state etc.

madig commented 2 years ago

This would also mean we'd need to stop allocating new sub-buffers while parsing?

cmyr commented 2 years ago

what sub buffers do we allocate?

madig commented 2 years ago

https://github.com/linebender/norad/blob/47ff135ae7b5f715b1a7400095920edb2cbf216f/src/glyph/parse.rs#L142

This one for example.

cmyr commented 2 years ago

mm, that is a funny one, I didn't remember that. That would be unchanged, although in theory we could also have a reusable buffer for that. I don't see any others, do you?

madig commented 2 years ago

That's probably the only one :)