‹ BackHN Continuity

Thread

UTF-8000: Unlimited UTF-8

133 points · 121 comments · vismit2000

Loading the complete thread in the background. This saved snapshot is available now. Refresh

  1. sph · · focus · HN ↗
    > UTF-8000 is in no way endorsed by or representative of the Unicode Consortium.

    Not until they decide to expand the emoji range, allocate space for all past and future fictional languages, as well as birdsong and dog barks.

    Someone at the consortium is rubbing their hands with glee with all the newfound space.

    But honestly, cool hack! If you invent a method to encode large numbers into bytes, why limit yourself to 24-bit numbers?

    1. flohofwoe · · focus · HN ↗
      > ...24-bit numbers?

      Technically current UTF-8 only goes up to 21 bits (that's the current UNICODE range), for the encoding itself that is an arbitrary limit though, with the 'single lead byte' method of traditional UTF-8 it could go up to 36 bits "payload".

    2. throw0101a · · focus · HN ↗
      > […] why limit yourself to 24-bit numbers?

      For compatibility with UTF-16:

          o  Restricted the range of characters to 0000-10FFFF (the UTF-16
             accessible range).
      
      * <a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc3629#section-12" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc3629#section-12

      * <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UTF-16" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UTF-16

      The original spec had 31 bits (the UTF-32&#x2F;UCS-4 range):

      * <a href="https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc2279" rel="nofollow">https:&#x2F;&#x2F;datatracker.ietf.org&#x2F;doc&#x2F;html&#x2F;rfc2279

      * <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UTF-32" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UTF-32

      1. orangeboats · · focus · HN ↗
        We really ought to deprecate UTF-16 someday. The fact that it pretends to be a fixed-length encoding has caused all sorts of bugs over the years, with many people assuming n(UTF-16 codepoints) == n(characters) which breaks when the string contains non-BMP characters.

        And also, for personal aesthetic reasons I hate that it limits the Unicode codepoint range to an awkward non-power-of-two number (0x110000 codepoints in total). UTF-8 and UTF-32&#x27;s 2^31 is much more natural.

        1. bjoli · · focus · HN ↗
          I wonder what it would take. For things like Java, JSA, and c# there would have to be things like a parallel utf8 api (yes please), but the really hard parts is the things that are as old as time (windows).

          I don&#x27;t think it will ever happen, but one can dream.

    3. sharktheone · · focus · HN ↗
      I think that wouldn&#x27;t change much. They would just make use of more grapheme clusters.

      For emojies they already make heavy use of the Zero-Width-Joiner. So a woman firefighter is the woman emoji + ZWJ + fire engine. Sure the UTF-8000 approach is much better encoding size wise.

      1. mitxela · · focus · HN ↗
        I wonder how they&#x27;re going to encode a female fire engine in the future.
        1. Dylan16807 · · focus · HN ↗
          No worries, that would use female sign, not woman.
        2. sharktheone · · focus · HN ↗
          I don&#x27;t understand why you are saying this. That just seems a bit inappropriate
          1. mitxela · · focus · HN ↗
            It&#x27;s a joke based on the construction of emojis? Female plus fire engine obviously denotes a female fire engine but has apparently been repurposed as a female firefighter instead
    4. TeMPOraL · · focus · HN ↗
      I predict eventual convergence between UTF-whatever and most popular tokenizer for whatever LLM escapes to become world-ruling AGI.

      I mean, if someone&#x27;s seriously going to try encoding birdsong and dog barks, at this point they&#x27;re basically reinventing tokens for multi-modal language models.

  2. Dwedit · · focus · HN ↗
    FF bytes are an easy way to identify an invalid UTF-8 file. This idea doesn&#x27;t have that property.
    1. sph · · focus · HN ↗
      [delayed]
      1. da_chicken · · focus · HN ↗
        Yes, I agree.

        It&#x27;s more common for programs that say they support UTF-8 to not really do so at all. It wasn&#x27;t that long ago that &quot;UTF-8&quot; support was often just single byte, so it was little more than ASCII. Even now it&#x27;s common for programs to choke on the optional BOM. Yes, it is redundant, congratulations. The spec still explicitly allows it. Three and four byte character support is still not the best, too.

        1. flohofwoe · · focus · HN ↗
          &gt; &quot;UTF-8&quot; support was often just single byte, so it was little more than ASCII

          &quot;Single byte UTF-8&quot; is ASCII. That&#x27;s one of its most important properties.

          &gt; Even now it&#x27;s common for programs to choke on the optional BOM

          And they should... BOMs (and especially the hilarious UTF-8 BOM) are strictly a legacy Microsoft&#x2F;Windows thing and should be abolished along with &quot;extended&quot; 8-bit ASCII encodings and UCS-2&#x2F;UTF-16 (only UTF-32 makes sense, but should only be used at runtime to allow random access on UNICODE code points, but not for data exchange.

          1. entrope · · focus · HN ↗
            &gt; BOMs (and especially the hilarious UTF-8 BOM) are strictly a legacy Microsoft&#x2F;Windows thing

            How should a reader infer the bye order for a UCS-2 or UTF-16 file without a BOM? It seems like one would have to read until finding a code point that would be illegal under one ordering (but files might not include such a code point).

            Similarly, a UTF-8 BOM is a useful flag to distinguish UTF-8 from other text encodings. You are right that the ambiguity goes away if those other encodings do, but people don&#x27;t want to rewrite their legacy files. Some people don&#x27;t want to use two bytes for common non-ASCII characters, so they are really attached to ISO-8859 or Windows-1252 or koi8r or whatever. CJK languages have their own encodings that are more efficient for their languages. UTF-8 is great for English speakers, but it&#x27;s a compromise for everyone else, so they might reasonably want incompatible systems for their own use. UTF-8 BOM is a good &quot;magic&quot; sequence to detect encoding as long as people have non-UTF-8 files.

            1. flohofwoe · · focus · HN ↗
              &gt; How should a reader infer the bye order for a UCS-2 or UTF-16 file without a BOM?

              Simple: switch to UTF-8 as the only encoding standard for sharing text data, keep UTF-32 as &#x27;internal&#x27; runtime format for random access to codepoints, and get rid of all other legacy encodings (UCS-2, UTF-16, Extended ASCII with code pages, and all the other region specific encodings that popped up in the 70s and 80s because UTF-8 wasn&#x27;t invented yet.

              This general switch to UTF-8 should have happend in the mid-to-late 1990s (e.g. together with the web becoming popular), and Microsoft alone is to blame for dragging this shit along for the next three decades. If all Microsoft tools would only save text data as UTF-8 starting by the end of the last century, but still support reading all sorts of encodings for a decade or so, the transition would have been finished by 2010. Alas, that never happened.

              And tbh, the file size argument for alphabets that don&#x27;t fit into 7-bit ASCII doesn&#x27;t really make sense anymore today where images and videos make up the vast majority of data volume.

          2. da_chicken · · focus · HN ↗
            Your opinion on the BOM isn&#x27;t wrong, but it&#x27;s also not germaine to whether or not you&#x27;re actually following the spec. The spec is the spec. If you don&#x27;t like it you can get the spec changed. You don&#x27;t get to ignore the spec and then claim support. That&#x27;s not how standards work. &quot;I don&#x27;t like it,&quot; isn&#x27;t a good explanation.

            Otherwise I&#x27;d be inclined to fix the spelling error in the HTTP referrer.

          3. Dwedit · · focus · HN ↗
            CJK characters is the one big weak point of UTF-8. It forces them to be 3 bytes large instead of the local codepage which is 2 bytes per character, or UTF-16 which is also 2 bytes per character.
            1. flohofwoe · · focus · HN ↗
              IMHO a 30 percent size increase for sharing text data is really not a problem when most data sharing happens via audio, video and image data.
    2. flohofwoe · · focus · HN ↗
      It&#x27;s still a joy to see how frigging elegant and extensible the UTF-8 specification is. And even without the esoteric 0xFF lead byte, the regular UTF-8 encoding with a 0xFE lead byte would still have plenty of headroom (36 bitts) compared to the current 21 bits for UNICODE.
    3. beeforpork · · focus · HN ↗
      As are FE, FD, FC, FB, FA, F9, F8, F7, F6 and F5.
    4. gzitscrux · · focus · HN ↗
      C0 and C1 can do so though according to the author.

      &gt; because all 4 of 2-byte UTF-8&#x27;s mandatory content bits lie in the first-and-final start byte, we can explicitly rule out 11000000 (0xC0) and 11000001 (0xC1) as permanently invalid bytes. They will never ever appear anywhere in a valid UTF-8000 code unit!

  3. achille · · focus · HN ↗
    &gt; Ken Thompson: &quot;...i really dont think it is useful. it is like replacing ipv6 with ipv50&quot;
    1. mitxela · · focus · HN ↗
      256-bit addresses would be long enough proper cryptographic addressing. (128 is barely not enough due to how they&#x27;re allocated)

      512 would also for cryptographic addresses within cryptographic subnets (or 3 128-bit layers plus some extra bits), and 1024 would allow for up to 7 layers. It&#x27;s not a completely silly idea.

      1. Dylan16807 · · focus · HN ↗
        Is there a significant reason to want those to use the same address space as the normal internet?
        1. mitxela · · focus · HN ↗
          The other option is to start making more software AF-agnostic and not assume that an address is always an ipv4 or ipv6 address.
  4. snvzz · · focus · HN ↗
    No project is ever safe from complicators.

    This is why we need the KISS enforcers.

    1. flohofwoe · · focus · HN ↗
      But the nice thing of UTF-8 is that this proposal isn&#x27;t really a &quot;complication&quot;, but a minimal and natural of the original idea to allow more than one lead byte.
      1. entrope · · focus · HN ↗
        Allowing more than one lead byte is a complication of the existing standard. As many others have pointed out, we have plenty of coding space without that (e.g. by allowing 5- and 6-byte UTF-8 again), so the case for the extra complexity is currently not compelling.
      2. snvzz · · focus · HN ↗
        It starts like this, and ends up like x86.
  5. flohofwoe · · focus · HN ↗
    Phew, and I was worried that we&#x27;d be running out of UNICODE space for new emojis ;)
  6. mrlonglong · · focus · HN ↗
    I love it.

    Some day we&#x27;ll need this when we finally realise we are not alone in the universe. Alien glyphs ftw.

  7. Grimeton · · focus · HN ↗
    More like WTF-8.
    1. Sharlin · · focus · HN ↗
      No, WTF-8 is its own encoding: <a href="https:&#x2F;&#x2F;wtf-8.codeberg.page&#x2F;" rel="nofollow">https:&#x2F;&#x2F;wtf-8.codeberg.page&#x2F;
  8. Sharlin · · focus · HN ↗
    UTF-8 originally supported up to six-byte encodings (see eg. RFC 2279), but it was restricted to four bytes in 2003 in order to match UTF-16 constraints :(
    1. delamon · · focus · HN ↗
      We still have about 85% of codepoint space unused. Hopefully, by the time it becomes a problem, UTF-16 will be long dead
      1. nasso_dev · · focus · HN ↗
        i hope so too, but UTF-16 being used by languages such as java and javascript makes me fear it might be here to stay.... i hope im wrong
        1. johnisgood · · focus · HN ↗
          [delayed]
        2. hnlmorg · · focus · HN ↗
          The number of glyphs available by adding additional bytes drops exponentially because each subsequent byte has one less bit available.

          So I think if we ever were in a situation where &gt; 1 million code points isn’t enough, then we should look at an entirely new way to serialise those code points anyway.

          1. delamon · · focus · HN ↗
            I don&#x27;t quite get it. 5-byte utf-8 encoding gets extra 5 bits compared to 4 byte, and 6-byte gets extra 10 bits. If you were thinking about bits in leading byte, then yes, you are losing one bit for every extra trailing byte, but you also get 6 bits from it. So adding a byte gives you extra 5 bits.
            1. hnlmorg · · focus · HN ↗
              Yeah, you’re right. I might have attempted to do mental arithmetic before coffee…
        3. 7bit · · focus · HN ↗
          Utf-16 is famously used by Windows for everything important as well.
          1. adornKey · · focus · HN ↗
            And UTF-8 isn&#x27;t even fully compatible with windows UTF-16 - UTF8 can&#x27;t encode a lot of truncated windows UTF-16 filenames.. You need WTF-8 for that.

            <a href="https:&#x2F;&#x2F;artoria2e5.github.io&#x2F;XB18030&#x2F;" rel="nofollow">https:&#x2F;&#x2F;artoria2e5.github.io&#x2F;XB18030&#x2F;

            It seems when designing Unicode most energy went into emoji. And there was nothing left for fancy things like fixed-length string buffers. The only explaination why UTF8 Buffers aren&#x27;t compatible with UTF16 Buffers... is a really strong emoji...

          2. colejohnson66 · · focus · HN ↗
            Thankfully, this is changing. Win32&#x27;s &#x27;A&#x27; ANSI&#x2F;ASCII APIs now support UTF-8 if your app declares such a wish. <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;69181417&#x2F;1350209" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;69181417&#x2F;1350209
        4. flohofwoe · · focus · HN ↗
          The internal string encoding of a programming language doesn&#x27;t really matter as long as it supports UTF-8 at the boundaries. E.g. the text encoding standard on the web is UTF-8, even though JS strings may be stored as UTF-16 in memory.
          1. account42 · · focus · HN ↗
            The internal string encoding and its limitations does leak into the APIs.
          2. bjoli · · focus · HN ↗
            The problem is the boundary with, say, windows. In rust they have WTF-8 more or less just to deal with windows filenames.
      2. colejohnson66 · · focus · HN ↗
        But by then, the 4-byte limit of UTF-8 will itself have ossified. Even today, reverting back to the 6-byte limit is nigh impossible.
        1. Razengan · · focus · HN ↗
          By then we will have quaternary quantum computers and FTL circuits where the information appears before you request it
  9. u1hcw9nx · · focus · HN ↗
    The reason for prefix code in UTF-8 compactness combined with legacy ASCII compatibility and frequency of use of certain code points. After you go past few bytes and commonly used codeponts it uses compactness.

    If you start from scratch, it would be better to just switch into LEB128 encoding.

  10. 2shortplanks · · focus · HN ↗
    On a practical matter, it seems like a bad idea to have codepoints that can take up to an arbitrary number of bytes - this just screams buffer overflow problems.

    So in practicality, you’re going to want an arbitrary limit on this (the article suggests as much). But if you place a limit on it then you’ve got one implementation of the standard that can decode certain characters and another that can’t. Better to have one standard that puts a hard limit on the number of bytes and another standard that uses more bytes and so on.

    1. flohofwoe · · focus · HN ↗
      OTH UTF-8 is just one variable-length stream encoding among many others (RLE, LBE128, etc...).
      1. DmitryOlshansky · · focus · HN ↗
        The bonus is synchonizing at arbitrary point in stream and that ASCII is UTF-8
      2. saghm · · focus · HN ↗
        Unless I&#x27;m misremembering, even UTF-16 is variable. You need to bump up to UTF-32 to get fixed-width.
        1. cyphar · · focus · HN ↗
          Even better, it&#x27;s arguably both -- surrogate characters are valid codepoint values so technically UTF-16 is fixed-width but programs need to have special handling for surrogate pairs meaning it is practically variable-width.

          Truly the worst of all worlds.

        2. mafuy · · focus · HN ↗
          Correct me if I&#x27;m wrong, but I think all kinds of UTF, including 16 and 32, support arbitrary length for a single effective character. This would be because you can stack modifications as long as you like.
          1. ElectricalUnion · · focus · HN ↗
            What you meant by &quot;single effective character&quot; is grapheme clusters. This whole discussion is about variable sized code points.
            1. Dylan16807 · · focus · HN ↗
              The first comment was kind of iffy when it was also talking about buffers and characters, and focusing on code points is mostly a bad focus. It&#x27;s worth bringing up so nobody thinks fixed width at a single layer is particularly useful, because other layers will still be variable.
        3. flohofwoe · · focus · HN ↗
          Yes, UTF-16 is the worst of all alternatives and should be abolished rather sooner than later.

          UTF-32 is fixed-width for UNICODE code points, but a single visual character (e.g. a &quot;grapheme cluster&quot;) can be built from multiple code points. This is not an encoding problem though, but mostly a problem for the high level code working with already decoded text data (text renderers, etc...).

          1. nickyvdicarlo · · focus · HN ↗
            I was working on optimizing a UUID scanner recently, and was baffled when I discovered that Java represents all char primitives in UTF-16, regardless of the original encoding.

            So even given an ascii String, if you want to do something like

            char c = input.charAt(index)

            the JVM is going to jump to that index, check whether the character at that index isLatin(), then cast that single byte into to a 2 byte char... every single time.

            in the naive solution, omething like 15% of the CPU cycles were spent checking isLatin() over and over again

    2. Retr0id · · focus · HN ↗
      In regular unicode, a grapheme can be made up of an arbitrary number of codepoints (and thus an arbitrary number of bytes), which does cause issues at times.
    3. saghm · · focus · HN ↗
      &gt; this just screams buffer overflow problems

      Without endorsing this specific idea, I think maybe after over half a century of C that this argument shouldn&#x27;t get in the way of a new standard. Pretty much every other language has managed to solve this problem, and the people who write new projects in C&#x2F;C++ have decided they&#x27;re not concerned about buffer overflows, so if someone decides to start a new project using something like this (or go out of their way to add support for it to an existing project), that&#x27;s kind of on them. The rest of computing shouldn&#x27;t get stuck in 1972 forever.

      1. drfloyd51 · · focus · HN ↗
        It’s not about the language. It’s about the runtime environment. Not everything is fully developed UI running on beefy CPUs with gigs of RAM.

        Sometimes the environment forces a language choice.

        1. saghm · · focus · HN ↗
          I&#x27;m failing to see why an embedded environment would have any need for a new encoding format, which is kind of my point: the types of things that are going to be written in C are not the ones going to be adopting completely new backwards-incompatible standards anyhow. If we refuse to try something based on how it would interact of the ecosystem that would likely never consider adopting something like it in the first place, we&#x27;re literally fixing our computing to constraints from half a century ago and counting. Nobody who is going to write C would stop because of something like a new Unicode scheme with much larger encoding widths, so why should that be an argument against it happening?
          1. strenholme · · focus · HN ↗
            “completely new backwards-incompatible standards”

            A reasonable person would assume you’re talking about UTF-8000. It’s not completely new: RFC2279, the original UTF-8 proposal, worked exactly like UTF-8000 for codepoints 31 bits or smaller in size. It’s not backwards-incompatible: UTF-8000 is exactly like UTF-8 for 1, 2, and 3-byte long codepoints, and like UTF-8 codepoints for 4-byte long codepoints with a value of 0x10_ffff or smaller (so all UTF-8 codepoints encoded with the first byte being 0b1111_00xx or starting with the bytes 0b1111_0100 0b1000_xxxx).

            It’s a backwards compatible way of encoding numbers in UTF-8 larger than 0x10_ffff or (0x7fff_ffff with the original RFC2279 proposal).

            I agree that C isn’t the best language to start a new programming project in. There are things I don’t like about Rust, mainly that there’s only one implementation of it, but if I were to start a new project needing the speed of a system programming language, it makes a lot of sense.

            1. saghm · · focus · HN ↗
              The original comment that I responded to said this:

              &gt; On a practical matter, it seems like a bad idea to have codepoints that can take up to an arbitrary number of bytes - this just screams buffer overflow problems.

              My response was that I don&#x27;t see &quot;it would be hard to write correct code for this in C&quot; to be a particularly useful objection. I&#x27;m honestly a bit confused by the reaction to my comments because it seems that every new reply seems to have an orthogonal objection to the previous one, but none of them seem to be actually addressing the point I&#x27;ve been trying to make.

      2. strenholme · · focus · HN ↗
        I agree C has a lot of problems. The nice thing about C is that it’s a rigorous standard (C90, C99, C23, etc.) with multiple actively maintained implementations (GCC, LLVM&#x2F;clang, TCC, etc.) so standards compliant C code should (in theory) compile and run for the foreseeable future.

        Python, Rust, Perl, etc. are all languages with a single actively maintained implementation and haven’t had the rigorous standardization C and POSIX utilities (Awk, &#x2F;bin&#x2F;sh, sed, etc.) have had.

        1. saghm · · focus · HN ↗
          &gt; standards compliant C code should (in theory) compile and run for the foreseeable future

          Yes, but the problem is that we have decades of examples of showing that even the best programmers in the world in practice will write code that isn&#x27;t &quot;standards compliant&quot; in a way that prevents UB.

    4. Pannoniae · · focus · HN ↗
      You don&#x27;t have a buffer overflow problem if you read it in a memory-safe way i.e. read it in chunks and realloc when you reach the size of your allocation.

      What you will have is a potential denial-of-service attack - although this one isn&#x27;t particularly great because there&#x27;s zero amplification (they might as well just send garbage into your firewall)

      1. torgoguys · · focus · HN ↗
        DOS in what way? Can you clarify? Thx.
      2. LorenPechtel · · focus · HN ↗
        Memory allocation?? Why? Real world, you&#x27;ll bump into limits based on fonts long before you&#x27;ll get a buffer that&#x27;s too large for the stack and worth using the memory allocator for. I can&#x27;t see any reason to support more than 2^64 characters and lots of headaches from trying to beyond that. You check your buffer writes and reject the character if it&#x27;s too long.
      3. zbentley · · focus · HN ↗
        I think the DoS has pretty common amplification vectors in the form of APIs that split or otherwise copy (e.g. materializing code points for Unicode regex searching).
    5. explodes · · focus · HN ↗
      Limit the codepoint to the number of atoms in the universe (less than 32 bytes).
    6. __david__ · · focus · HN ↗
      I don’t think there’s harm is speccing out the arbitrary encoding and then having a different spec that references that spec but puts hard limits on it. Many rfcs are like that.
  11. jibal · · focus · HN ↗
    The letter from Ken Thompson is spot on:

    &quot;your first 2 extensions (5 and 6 bytes) were clearly envisioned. the standard (up to 4 bytes) was created to cover the size of unicode. i thought any more description would be a waste of paper. i think your extension from 7 to 8 bytes is a little hoaky. i requires reading the whole string rather than &quot;knowing&quot; the number of follow on bytes. so, i think the only thing new is the 7 byte version.

    i appreciate the mail, but i really dont think it is useful. it is like replacing ipv6 with ipv50.&quot;

  12. yyyk · · focus · HN ↗
    [delayed]
    1. mitxela · · focus · HN ↗
      Important to recognize that characters have individuality, that&#x27;s why there can only be a limited number of them. Anything without this property - any generic form of encoding - is not characters, it&#x27;s something else like images. If it&#x27;s not in any alphabet it shouldn&#x27;t be in unicode, you should use an escape tag for image data instead. (Emojis probably shouldn&#x27;t, but they do behave like an alphabet)

      There cannot be 4 trillion characters because humans would need to know all of them and humans cannot know that many things.

  13. rsanheim · · focus · HN ↗
    This is like TIME CUBE (<a href="https:&#x2F;&#x2F;www.timecube.net&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.timecube.net&#x2F;) but for encoding nerds.
    1. sph · · focus · HN ↗
      timecube.com is lost, zombo.com has been redesigned. If this is not proof of a dead internet, I don’t know what is.
    2. strenholme · · focus · HN ↗
      That’s a pretty harsh comparison.

      It’s a fairly simple encoding which is UTF-8 compatible and allows codepoints to be arbitrarily large. It’s a real encoding proposal with a simple rigorous specification. I don’t have a use case for needing arbitrarily large codepoints, but for people who do, this makes more sense than hacks such as having surrogates in Unicode’s hi-bit private use area.

  14. beeforpork · · focus · HN ↗
    It would be nice if the first paragraph gave a motivation for this. Why did you start this?

    I mean, I can derive from the text that this can encode arbitrarily large integers. So what? What&#x27;s the point? I also understand that this is for fun.

    1. conradludgate · · focus · HN ↗
      &gt; This is a fun standalone project &#x2F; proposal
      1. beeforpork · · focus · HN ↗
        Yes, sure. But what was the incentive? The goal? The reason to start the project (and not another one)? What was interesting enough to start this?
  15. mqus · · focus · HN ↗
    Some ideas of what to do with this space:

    - fully-customizable emojis (think of a RPG-like character customization screen)

    - heck, why not full jpegs&#x2F;gifs?

    - some unicode programming script (running Doom)

    - ?

    That said, some very minor (HN-style) nitpick:

    &gt; Otherwise for an n byte code unit this is (5n+1) &#x2F; 8n, that is 5n+1 content bits out of a total of 8n bits from n bytes. We can rewrite this as (5&#x2F;8) + 1&#x2F;(8n) which moderately quickly approaches 5&#x2F;8 = 62.5%. It is nice that this limit is nonzero and does not depend on n.

    Isn&#x27;t a limit by definition no longer dependent on n?

    1. jeroenhd · · focus · HN ↗
      U+E000–U+F8FF, U+F0000–U+FFFFD, and U+100000–U+10FFFD can already provide you with your own emoji, as that range has been reserved for private use. Extending the range further might make sense if you need even more space in your program, but that&#x27;s a lot of space already.
      1. grumbelbart · · focus · HN ↗
        The point is probably to encode the emoji (image) in the codepoint itself.
      2. mqus · · focus · HN ↗
        2-3 bytes are not much space for anything. Sure, you could use multiple successive ones of these code points and define your own &quot;continuation&quot; encoding in these ranges, but that doesn&#x27;t seem right to me somehow
        1. flohofwoe · · focus · HN ↗
          That combination is how it already works. You can build combined &quot;characters&quot; (grapheme clusters) from multiple code points, e.g. you could have a &quot;base emoji&quot; followed by a &quot;modifier&quot; emoji, and AFAIK that&#x27;s how emojis with different skin colors work (one code point for the base emoji (e.g. &#x27;thumbs up&#x27;), and a skin color modification code point with can be applied to all emojis that involve skin color.
    2. xg15 · · focus · HN ↗
      &gt; some unicode programming script (running Doom)

      I agree with you that Unicode urgently needs a scripting capability (*), but my plan was to just implement it using invisible tag characters [1] or something like that - but of course implementing it in a single codepoint is the much more elegant solution.

      (*) in RFC 04-01-2027

      [1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tags_(Unicode_block)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Tags_(Unicode_block)

      1. reaperducer · · focus · HN ↗
        in RFC 04-01-2027

        I, for one, welcome our new time-traveling overlords.

    3. mqus · · focus · HN ↗
      One more idea:

      - Unicode-as-a-character, meaning: a whole text displayed as if it were one character, made for infinite zooming

    4. sph · · focus · HN ↗
      [delayed]
    5. amelius · · focus · HN ↗
      Imagine someone using the same fully customized emoji multiple times in the same text. Seems like a waste of space. Maybe better to encode just a UUID, and send the image codebook separately.
    6. Lockal · · focus · HN ↗
      &gt; - some unicode programming script (running Doom)

      &gt; - ?

      Bad Apple, oh, wait: <a href="https:&#x2F;&#x2F;github.com&#x2F;hsfzxjy&#x2F;Bad-Apple-Font" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hsfzxjy&#x2F;Bad-Apple-Font

  16. lukasgelbmann · · focus · HN ↗
    Self-synchronization in UTF-8 is intuitively a great thing to have, yet I don’t remember actively relying on it ever. Does anyone have a good example of when it‘s useful?

    Another related nice property that UTF-8 has: substring search reduces to bytestring substring search. I.e. given two Unicode strings in UTF-8 encoding, you can check if one is a substring of the other by just treating them as bytestrings and checking if one bytestring is a substring of the other bytestring. This is a stronger property than self-synchronization: UTF-8 has it, but UTF-8000 doesn’t.

    1. hippietrail · · focus · HN ↗
      Only if they&#x27;ve already both undergone normalization to NFC or NFD.
    2. conradludgate · · focus · HN ↗
      Rely on it? Not that I can remember.

      However, Rust makes use of it for fast safety checks. Because rust strings must be valid utf8, if you want to take a substring at some range, eg &quot;Hello, World!&quot;[7..12] then it&#x27;s very simple to just check bytes 7 and 12 and see if they are the start of a codepoint, no other scanning or parsing is required.

    3. tjjfvi · · focus · HN ↗
      I don’t see how UTF-8000 doesn’t have it. The first byte of any code point is either 0xxxxxxx or 10xxxxxxx, which is distinct from all non-first bytes which are 11xxxxxx. Thus any UTF-8000 sub-bytestring must necessarily have the start aligned at a code point boundary, at which point all the subsequent bytes are interpreted as codepoints in the same way.
      1. lukasgelbmann · · focus · HN ↗
        Right, UTF-8000 does have this property. Too late to edit my comment now, thanks for noticing that.
    4. sparkie · · focus · HN ↗
      Self-synchronization is useful for substring matching, as it means just matching the bytes.

      Without, you could match bytes that are a partial codepoint.

    5. layer8 · · focus · HN ↗
      &gt; Does anyone have a good example of when it‘s useful?

      It prevents vulnerabilities where an incorrect offset into a string could result in characters being read that aren’t in the original string (which could defeat a prior sanitization of the string).

    6. rurban · · focus · HN ↗
      Only if its normalized unicode. Most strings are not, and utf-8 does not guarantee normalization.
    7. yencabulator · · focus · HN ↗
      [delayed]
  17. lifthrasiir · · focus · HN ↗
    I was about to immediately suggest UCS-X, and then pleased that the author offers a fair comparison to UCS-X and many other alternatives. Great. Too bad UCS-X is possibly more memorable name.
  18. etatoby · · focus · HN ↗
    Finally, an ASCII-safe way to encode all the vectors of Neuralese.
  19. avadodin · · focus · HN ↗
    IIRC UTF-8 proposal used to go to 6 bytes as they already felt that not having part of the code point in the first byte was an issue somehow.

    I think at least 7 should be allowed. 42 bits could contain all sorts of information.

    &quot;UTF-8000&quot; is still ANSI-safe and although it loses some of the properties such as a header code only appearing once in a byte sequence, it is perfectly viable to encode arbitrarily sized unsigned integers.

  20. imhoguy · · focus · HN ↗
    Alright, so now we can fit an entire LLM model into one character.
  21. stbenjam · · focus · HN ↗
    &gt; No special cases introduced. All properties preserved.

    I don’t actually know if this is LLM-generated, but phrasing like this is weirdly triggering to me now

    1. Neywiny · · focus · HN ↗
      Yeah that kind of line is what I see all the time in my chats. Even worse worse is when they put it in code comments.
    2. account42 · · focus · HN ↗
      It&#x27;s not even true as being able to tell the character length from the first byte is not a property that extending UTF-8 past 36 bit payloads preserves.
  22. OutOfHere · · focus · HN ↗
    Perhaps we can use a generalized encoding space for LLM tokens. A tokenization scheme uses up a few hundred thousand entries, with say one thousand new entries added annually. These can be called amojis, meaning AI mojis.
  23. tescreal · · focus · HN ↗
    On the naming issue with a &quot;UTF-8&quot; prefix, I suggest &quot;UTF+8&quot; which puns earlier in the string for a double effect. Fun paper!
    1. Rendello · · focus · HN ↗
      Or UTF-∞
    2. yencabulator · · focus · HN ↗
      [delayed]
  24. bastawhiz · · focus · HN ↗
    At some point it just collapses into a sort of Huffman coding of every possible 4096 bit embedding vector.
  25. phyzome · · focus · HN ↗
    Logo and name need more work but other than that, ship it.
  26. derefr · · focus · HN ↗
    On the opposite end of the spectrum from this idea, I&#x27;ve been thinking for a long time now that much of what&#x27;s weird&#x2F;redundant about Unicode comes from its self-synchronization requirement. And that you could create a very compact and expansive &quot;re-embedding&quot; of Unicode if you dropped this requirement.

    Self-synchronization is the idea that if you take an arbitrary Unicode stream, and then do any combination of 1. flipping bits in it at random, 2. injecting random extra whole bytes into the stream, and 3. dropping random whole bytes from the stream, then each such change will corrupt at most corrupt one Unicode code-unit in the stream. No such change will corrupt the stream itself so as to leave the stream in an invalid&#x2F;indeterminate state that a Unicode parser can&#x27;t know how to recover from.

    Unicode encodings are self-synchronizing at the byte-pattern level. But, much less often discussed, Unicode itself is also designed to be self-synchronizing in how it encodes interactions between code-units. And this really constrains how certain Unicode features can be, and historically have been, designed.

    If you want a run of Unicode code-units to all be &quot;tagged&quot; or &quot;colored&quot; with some property, then, due to the self-synchronization requirement (i.e. due to the assumption that any single one of those bytes could be corrupted or blown away, including whatever metadata-encoding bytes your scheme wants to use), you have to either:

    - define a &quot;pre-colored&quot; alphabet, and express your tagged content in that alphabet. (Think of e.g. the Unicode flag codepoints [<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Regional_indicator_symbol" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Regional_indicator_symbol], which are essentially a special namespaced copy of the roman upper-case alphabet intended to be used only to spell out two-letter contiguous pairs that are [or at some point were] valid ISO country codes; where, when used in this way, the resulting &#x27;colored&#x27;-letter-pair sequence has &#x27;flag semantics&#x27;, i.e. is meant to be rendered as a flag and machine-legible as a flag)

    - or individually tag each and every one of those codepoints with its own tag&#x2F;color codepoint (as in Unicode variation selectors)

    - or use &quot;operator&quot; codepoints that successively construct what are essentially in-memory codepoint cons cells, forming data structures that get treated as single grapheme-clusters with their own semantics (as in e.g. ZERO WIDTH JOINER used in its role in constructing complex emoji)

    These encodings are all very high-overhead; but these are the kinds of trade-offs you have to make for self-synchronization to work.

    And these trade-offs are sensible to make... if you&#x27;re Ken Thompson in 1992, having to consider e.g. plaintexts being transmitted over raw RS232, or filesystems that just blast bytes to a spinning-rust disk without so much as a checksum, and then read them back &quot;blindly&quot; years later with that disk potentially highly-degraded.

    But what if you live in the modern world, and you only care about holding and manipulating known-length strings in memory and&#x2F;or embedded into code-signed (and thereby hashed) binaries; transmitting data over TLS-based protocols where packet-level corruption causes retransmission; and checksummed-block filesystems over NVMe?

    Well, then you could define a much-more-concise reformulation of Unicode, that uses all the &quot;forbidden&quot; semantics-encoding techniques that Unicode itself avoids due to the self-synchronization constraint.

    Where by &quot;reformulation&quot;, I mean: a standard that keeps parity with Unicode in terms of what it can encode; and which at all times maintains a clearly-defined lossless bijective transformation between it and Unicode, evolving in lockstep with Unicode; but where Unicode and this formulation have their own distinct universes of codepoints, that compose using different rules, into the same ultimate sets of reachable grapheme-clusters with the same text-segmentation&#x2F;collation&#x2F;etc semantics.

    I&#x27;m honestly kind of surprised that there isn&#x27;t already a project somewhere to define an alternative Unicode formulation that looks like this.

    It&#x27;d not only be potentially a highly-efficient representation for many in-memory string operations (that text shaping libraries would also love); it&#x27;d also likely perform impressively (compared to regular UTF-8) as a canonical representation for documents used to train+prompt LLMs. It&#x27;d give &quot;more meaning per token&quot;, via all the repeated-per-codel overhead becoming once-per-sequence overhead; and it&#x27;d also allow many layers of meaning that are currently encoded via in-band protocols (ANSI escape codes, Markdown, HTML&#x2F;XML, etc) that the LLM needs to learn additional recognition logic for, to instead be parsed out &quot;during&quot; initial text-stream recognition.

    (And it&#x27;s taking me real willpower not to go into depth on all the features such a formulation could have, and all the benefits it could provide. I should probably stop here before I nerd-snipe myself!)

  27. jonhohle · · focus · HN ↗
    Why encode the length at all in the extension? Either the next byte is a continuation byte or not. Are there real world use cases where the length encoding is used in UTF-8 where individual bytes don’t have to be read anyway (for example, codepoint counting, but in practice what good is that without knowing if the code points are combining)? Even in the case where you just want a byte count, an invalid UTF-8 stream won’t respect the first count marker. The arbitrarily sized count is no better than an arbitrarily sized code point - you’d still have to handle all the same resource and sizing issues for safety. And then what, are you going to allocate a buffer that can fit a length that needs more than 64-bits to represent?
    1. kragen · · focus · HN ↗
      It&#x27;s a brilliant hack. It means that when you&#x27;re dealing with valid UTF-8 strings, various kinds of string relationships enjoy a homomorphism between byte strings and Unicode strings. Specifically, where S and T are Unicode strings and E is the UTF-8 encoding operation:

      • E(S concatenated with T) = E(S) concatenated with E(T)†

      • S starts with T iff E(S) starts with E(T)

      • S ends with T iff E(S) ends with E(T)

      • S contains T iff E(T) contains E(T)

      This means that, as long as you know your encoded strings don&#x27;t contain invalid UTF-8, you can do a great deal of your string processing on the byte-encoded form, which is enormously faster than decoding the strings before doing the string processing, permits efficient radix-256 tries, and is much smaller in many common cases.

      It also bounds the work you have to do if you&#x27;re processing a string starting from the end, while certain other encodings require looking back in the string arbitrarily far to figure out how to interpret the bytes you&#x27;re looking at. This is particularly important for Boyer–Moore string search, but in many cases it&#x27;s also an express trip to getting your code featured on <a href="https:&#x2F;&#x2F;www.tumblr.com&#x2F;accidentallyquadratic" rel="nofollow">https:&#x2F;&#x2F;www.tumblr.com&#x2F;accidentallyquadratic.

      In short, yes.

      ______

      †Surprisingly, even this most basic homomorphism is not true of many other character encodings, which may need extra bytes to be inserted in between.

    2. faithful_droog · · focus · HN ↗
      Having the length of encoded in each codepoint means that you know if a stream ends at codepoint boundary or if it has a truncated final codepoint. You could probably do away with the length and maintain this property if you had distinct forms for start, continuer-mid and continuer-final bytes.
  28. strenholme · · focus · HN ↗
    I have entertained ideas like this every since becoming familiar with the original RFC2279 UTF-8 well over two decades ago, before UTF-8 was subsequently restricted to 21 bits.

    Another idea that would work is to start an encoding with 0b10xxxxxx have subsequent 0b10xxxxxx bytes continue the encoding, and end it with 11xxxxxx. 0b10000000 (i.e. 128) is not allowed, and we add 127 to the resulting number (so each code point has only one representation) This way, the ♥ symbol (that’s 0x2665 or 9829 in decimal) would be represented as follows:

    0b0010011001100101 → 0b0010010111100110 (subtract 127) → 0b10000010 0b11010111 0b11100110

    This allows 18 bits to be encoded in three bytes, and, like UTF-8000, allows arbitrarily long sequences.

    In the real world, the last time I needed to have a custom encoding, I went the other way and converted Unicode in to a 7-bit ASCII compatible encoding, where most ASCII control characters were converted into glyphs, as follows:

        0123456789abcdef
      0 .ÁÉÍÑÓÚÜ¡..—..«»
      1 •áéíñóúü¿‘’.→“”©
      2 .!&quot;#$%&amp;&#x27;()*+,-.&#x2F;
      3 0123456789:;&lt;=&gt;?
      4 @ABCDEFGHIJKLMNO
      5 PQRSTUVWXYZ[\]^_
      6 `abcdefghijklmno
      7 pqrstuvwxyz{|}~♥
    
    “.” represents a control character here; only “null” (0x00), “line feed” (0x0a), “form feed” (0x0c), “tab” (0x09), “carriage return” (0x0d), and “escape” (0x1b) are control characters; the rest are printable glyphs. I used this character set for my blog: Since my blog is processed using HTMLDOC (which I learned the hard way is buggy with full Unicode) and my own Lua script.

    With Lua, Unicode regexes are not readily supported because its regular expression engine assumes a codepoint is only one byte long when forming character classes such as %u for upper case letters. My Lua code has character classes for the non-ASCII glyphs such as %t for all letters in this custom encoding.

    I have made this encoding 7 bits because that gives me the option to use the eight bit for future expansion.

    The real reason for so few glyphs is because, in addition to having things work nicely with code which assumes 8-bit codepoints, with the modern web, I need to send to the viewer the font a page will be rendered with (it would had been nice if Microsoft had open sourced Verdana, Georgia, and the rest of the core fonts, and if those fonts became a part of the browser standards, but oh well), so I aggressively subset the font to minimize the page load time.

    1. strenholme · · focus · HN ↗
      Actually, my proposed encoding only needs to add 64 to the code point (or subtract 64 when encoding a code point), not 128. That in mind, ♥ is encoded as follows:

      ♥ → 0b0010_0110_0110_0101 → 0b0010_0110_0010_0101 (subtract 64) → 0b10_00_0010 0b10_0110_00 0b11_10_0101

      Code point 128 is encoded as follows:

      128 → 0b1000_0000 → 0b0100_0000 (subtract 64) → 0b10_0000_01 0b11_00_0000

      C99 can do up to over 10 bytes long (uint64_t) without a bignum library since 10 bytes gives us 60 bits. C23 gives us a bignum library so the sky’s the limit.

      Again, I only need 7 bits to represent every character the font for my blog has.

      1. strenholme · · focus · HN ↗
        Another extension to this encoding: If we have an 0b11xx_xxxx byte which isn’t proceeded by a 0b10xx_xxxx byte, the numeric value of the byte is its corresponding codepoint. This gives us all of the accented letters western European languages use, allowing us to represent all of ASCII and all western European letters with only one byte.

        This also means that the top half of ISO 8859-1 will have two representations with this encoding, but since they are letters, with the only symbols being × (multiplication) and ÷ (division), this should not be a security risk, unless one programs in Raku (which, ugh, gives meta significance to non-ASCII Unicode symbols).

  29. zahlman · · focus · HN ↗
    Since the Unicode Consortium isn&#x27;t going to actually assign those code points, this is functionally just a scheme for encoding variable-length integers designed as an extension of UTF-8 more or less arbitrarily.

    There&#x27;s a long history of designs for these (<a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Variable-length_integer" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Variable-length_integer) that the author might be interested in. I used to think about these things myself, including the &quot;zigzag encoding&quot; for signed values (not a difficult idea; this &quot;marvelous bijective mapping&quot; is the standard one used in math class to demonstrate that the integers are countable, and the nice implementation properties are a consequence of the choice to &quot;zig&quot; from 0 to -1 first combined with how two&#x27;s-complement works).

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.