v1.0.1 — shaping performance
Patch release from profiling the v0-vs-v1 benchmark.
Fixed
68% of generation time was a bug in arabic-reshaper 3.0.0. Its ligature-regex cache is guarded by hasattr(self, '__ligatures_re') but written to self.__ligatures_re — which Python mangles to _ArabicReshaper__ligatures_re inside the class body, while the string literal passed to hasattr is not mangled. The guard checks a name that is never set, so the regex was rebuilt on every call, re-reading ~290 configparser entries. Laying out one page called it ~1,800 times.
Mitigated inside ocrsmith.text.shaping: results are cached (shaping is a pure function of the string), and the reshaper's cache is warmed once so the library's own guard fires from the second call.
2,000 distinct strings: 26s → 0.36s.
Changed
Wrapping now measures a line by summing word advances plus space advances, which is how the renderer actually draws it. This is a correctness fix as well as a speed one — the two could previously disagree about where a line ends.
Numbers
- Test suite: 95s → 20s
- End-to-end generation: ~1.6× faster
- 460 tests pass; ligature formation and the additive measure are now pinned by tests
Full detail in CHANGELOG.md.