chiark / gitweb /
Bodgy fix for poor performance of wcwidth.
authorSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 17:56:45 +0000 (17:56 +0000)
committerSimon Tatham <anakin@pobox.com>
Fri, 8 Dec 2023 17:56:45 +0000 (17:56 +0000)
commit9819209e530fb943e7ba9a3d46ed25a01880de17
tree9cdb9c71aa5b6c4fedb2be8682e6803f441d587c
parent3710d1381669531623e35315226fc05bb0cdd0a6
Bodgy fix for poor performance of wcwidth.

Mastodonochrome was running rather slowly, and when I profiled it, it
turned out the bottleneck was the 'wcwidth' Python module, which is
not a wrapper on the C function, but a reimplementation in pure Python
and therefore not very fast.

I've bodged it by just making one big cache of all the strings that
the program ever passes to wcwidth, since there were only two calls to
that function at all and they were both in text.py. I don't know if
that's the right fix in the long term, but it seems to have improved
things considerably for now.

(Also, while I'm at it, ColouredString now wcwidths its contents once
at construction time and doesn't redo it on every call, so it doesn't
even look up the same thing in the cache multiple times.)
text.py