fontcrunch is slow because I can't handle references and lifetimes #35
Comments
@cmyr If you have any advice I would appreciate it. :-/ |
Can take a look in a few minutes. 👍 |
Thank you! I just had a flash of inspiration when washing up and I think the answer might be "change the data structure to avoid using a linked list". If we use a |
avoiding a linked list is definitely the first thing I would try. taking a look now, will see if I have any more concrete advice.. |
Original C++ is here if it helps: https://github.com/googlefonts/fontcrunch/blob/main/src/fontcrunch/quadopt.cc I just realised one of the Vec's was being used as an Option, so fixed that. |
There's a lot going on here, and I don't know a ton of the details, but some thoughts: if any of these vecs are fixed size, or have generally small sizes, I would look into using either an array or some sort of 'smallvec' type, like Instead of a linked list, my first thought would be to have a big shared vec (or |
Thanks for this. I have now switched it to using an Rc to hold the Statelet to ensure copies are cheap, but the performance problem is the same, so my intuition (copying the statelet lots of time was slow) doesn't seem to have been correct. Time to actually use a profiler and find out what's going on. |
OK, I was kind of optimizing the wrong thing. Moving to Rc did make it faster, but the real problem was indeed allocating lots of tiny vecs in the |
The ported version of fontcrunch is much slower than the original, particularly in glyphs which go down this O(n^2) loop:
fonttools-rs/crates/fonttools-cli/src/bin/fontcrunch.rs
Lines 322 to 332 in 0400715
I'm sure it's because of this clone:
fonttools-rs/crates/fonttools-cli/src/bin/fontcrunch.rs
Line 366 in 0400715
The clone is only there because I can't work out the lifetimes required for storing
Statelet
s as references within aStatelet
and moving them around. If I put what I think are the right lifetimes on the State and Statelet types, I get a confusing error like so:The text was updated successfully, but these errors were encountered: