Cut per-frame text tail and label allocations

- Font: walk UTF-8 codepoints in place instead of building a vector;
  reuse the texture-cache key buffer on the hit path.
- Text tails: show/ShowAll test isShowing (kept equal to list
  membership) instead of a linear find per tail, which made the
  per-frame ShowAllTextTail O(N^2); memoize label widths measured by
  both Arrange and Render.
- Tail painter reuses one CGraphicTextInstance and font name.
- CGraphicTextInstance::Render no longer copies the text unless secret.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-12 16:16:48 +09:00
co-authored by Claude Opus 5.5
parent 33552b9eeb
commit 4662e06b35
5 changed files with 41 additions and 23 deletions
+9 -4
View File
@@ -615,16 +615,21 @@ static PyObject* texttail_register_item(PyObject*, PyObject* args) {
void initTextTail() {
// Use the same FreeType font path as UI text, preserving the Retina render
// scale. SDL_RenderDebugText's fixed bitmap font is only a host fallback.
// One reused instance per callback: text tails paint several labels per actor per frame.
static auto fontFor=[](UI::CGraphicTextInstance& text,int& lastSize,float scale) {
const int size=int(12 * scale);
if(size!=lastSize){lastSize=size;text.SetFontName(("Tahoma:" + std::to_string(size)).c_str());}
};
TextTailManager::Instance().SetTextPainter(
[](float x,float y,const std::string& value,uint32_t color,float scale,bool outline) {
UI::CGraphicTextInstance text;
text.SetFontName(("Tahoma:" + std::to_string(int(12 * scale))).c_str());
static UI::CGraphicTextInstance text;static int lastSize=-1;
fontFor(text,lastSize,scale);
text.SetValue(value.c_str()); text.SetFontColor(color);
text.SetPosition(x,y); text.SetOutline(outline); text.Render();
},
[](const std::string& value,float scale) {
UI::CGraphicTextInstance text;
text.SetFontName(("Tahoma:" + std::to_string(int(12 * scale))).c_str());
static UI::CGraphicTextInstance text;static int lastSize=-1;
fontFor(text,lastSize,scale);
text.SetValue(value.c_str()); int width=0; text.GetTextSize(&width,nullptr); return float(width);
});
static PyMethodDef methods[] = {