UTF-8 String Indexing Strategies
The article does not mention Python, other than to reference CPython&#x27;s &quot;Flexible String Representation&quot;. However, it&#x27;s interesting that alternative Python implementations have decided against that model and indeed use UTF-8 strings internally.<p>MicroPython saves memory by simply making indexing into its strings O(n) [1], while PyPy&#x27;s UTF-8 strings have &quot;an optional extra index data structure to make indexing O(1)&quot; [2].<p>For compatibility, of course, Python implementations have to provide indexing of code points - it would be interesting to examine the pros &amp; cons of the different string representations. I wonder if new high-level languages would be better off using one of these representations, or taking the Go&#x2F;Julia approach of only indexing bytes.<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;micropython&#x2F;micropython&#x2F;blob&#x2F;a4f1d82757b8e95c21a095c99b7c3f04ded88104&#x2F;py&#x2F;objstrunicode.c#L156" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;micropython&#x2F;micropython&#x2F;blob&#x2F;a4f1d82757b8...</a><p>[2] <a href="https:&#x2F;&#x2F;twitter.com&#x2F;pypyproject&#x2F;status&#x2F;1095971192513708032" rel="nofollow">https:&#x2F;&#x2F;twitter.com&#x2F;pypyproject&#x2F;status&#x2F;1095971192513708032</a>