For a longer string (the above program with LEN = 2000 and N = 1), the binary search loop and pango_layout_get_unknown_glyphs_count clearly become dominating, while finding a fallback font takes little time.
The whole program:
cpu time: 3622 real time: 3668 gc time: 12
That won't hold in the general case, though, where my labels are multiple characters long with mixes of the problematic characters.
I suspect that would help my case, since there's a small finite set of characters for labels; this won't address whatever pango_layout_get_unknown_glyphs_count is, though.
Could we precompute the values of ok-count for the whole string (possibly skipping that if we know it won't be needed)? That might get from O(N^2 \log N) to O(N), no?
Thanks! Much of what was said there has been said here too, but one comment that @mflatt made that seems worth bringing over is:
It's also possible that upgrading Pango (and maybe adjusting things like whether fallback is handled manually on the Racket side) would address issues. I'm not sure how Pango has evolved for Mac OS, though, and building a new version of the library is probably not easy.