TurboWarp / extensions

User-contributed unsandboxed extension gallery for TurboWarp
https://extensions.turbowarp.org/
MIT License
114 stars 233 forks source link

New extension: Numerical Encoding V2 #1450

Closed GarboMuffin closed 4 months ago

GarboMuffin commented 4 months ago
  1. Replaced separate commands and reporters with just reporters (no more ugly global state that can get broken by unlucky warp timer)
  2. Significantly optimized encoding format.

The original extension always uses 6 numbers per UTF-8 character in the original text. On ASCII this has an efficiency of 1.33 bits/number.

https://github.com/TurboWarp/extensions/issues/1449 proposed length-prefixed encoding which is a good improvement for pure ASCII strings. Most of the commonly used parts of ASCII have 2 digit or 3 digit decimals codes so let's just say it's an average of about 3.5 numbers per character in the input after adding the length prefix. That's about 2.28 bits/number of efficiency.

This PR does all encoding and decoding operations on UTF-8 binary instead. Each group of 3 bits in the binary is encoded by 1 decimal in [1, 8] (not using 0 to avoid leading zeros), so this has 3 bits/number of efficiency.

In theory we should be able to get $\log_2{10} \approx 3.321$ bits/number of efficiency with some smarter encoding. But I think this is already pretty good and the encoding/decoding routines shouldn't be too hard to port to other languages for people making bots.

snowboyz0825 commented 4 months ago

As dumb as it is I'm proud I actually encouraged making an extension better and had it get better