mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-10-14 21:20:48 +08:00
Every traffic refresh rebuilt the attributed-string dictionary (font, color, paragraph style, baseline number, dict) and ran a CoreText layout via NSAttributedString::size() just to size the status item, although both depend only on the button height and the glyph advance. The dictionary and the monospaced per-glyph advance (measured once through the same layout engine with a "0" probe) are now cached keyed by button height, and the width is computed as longest-line length times the advance. The speed charset is pure ASCII on a monospaced font, so the arithmetic width matched the layout width exactly (max deviation 0.000pt over 2000 realistic samples). Standalone A/B over 43,200 updates (12h at 1 Hz), same hot path: | variant | mean | p95 | phys_footprint after | | --- | ---: | ---: | ---: | | rebuild + layout (old) | 6.89us | 7.8us | 19.8MB | | cached attrs | 4.71us | 5.0us | 7.8MB | | cached + arithmetic width | 0.27us | 0.3us | 6.0MB | The retained-memory delta is malloc-zone fragmentation from the churn, which this removes at the source.