Put a glyph's offset on the grid where it is placed

A placed glyph's offset is whole pixels by construction -- a floored pen
position plus the entry's integer bearing -- and `Painter::glyphs` was
converting it, and the entry's width and height, from `f32` on every frame
that drew the glyph. It is a `PxVec2` now, converted once when the text is
placed, and the size is two integer shifts.

Measured with `perf stat -e instructions:u`, since the difference is smaller
than this machine's clock: the `many` phase went from 2,013,099,594
instructions to 1,938,264,572 over 500 frames, 3.7% less. `scroll` and
`repaint` are unchanged to within noise, which is right -- they do not redraw
glyphs.

Checked: fmt, clippy, 105 tests, the reorder fuzzer at 300 seeds, and `tabs`,
`text` and `random` byte-identical.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
iris-aiandClaude Opus 5 committed 2026-09-16 04:11:07 -04:00
1 parent f11f5f4825
commit 11c55bcef9
4 files changed
+24 -9

No files matched your search

+7 -3
View File
@@ -326,9 +326,13 @@ impl<'a> Painter<'a> {
let mut region = origin;
region.x.end = region.x.start;
region.y.end = region.y.start;
let mut region = region.offset(UiVec2::px(glyph.offset));
region.x.end = region.x.start + UiScalar::px(glyph.entry.width as f32);
region.y.end = region.y.start + UiScalar::px(glyph.entry.height as f32);
let mut region = region.offset(UiVec2::from_px(glyph.offset));
let size = PxVec2::new(
Px::from_int(glyph.entry.width as i32),
Px::from_int(glyph.entry.height as i32),
);
region.x.end = region.x.start.offset(size.x);
region.y.end = region.y.start.offset(size.y);
self.write(
kind,
GlyphPrimitive {