fasttime / JScrewIt

Write any JavaScript with six characters: ! ( ) + [ ]
https://jscrew.it
ISC License
161 stars 13 forks source link

Batch `atob()` conversion #41

Open claybiockiller opened 1 year ago

claybiockiller commented 1 year ago

Currently, there is only 1 triplet has batch atob() definition: "mCh" == atob("bUNo"). But there are more triplets which batch atob() definition are practical: "#!/" (common in URL hashbang grammar) currently costs 1989 chars, while atob("IyEv") only costs 1942 chars; "{b:" (sometimes can be seen in object definitions) currently costs 1121 chars, while atob("e2I6") only costs 961 chars; "www" (well-known part of domain name) currently costs 990 chars, while atob("d3d3") only costs 900 chars. But batch atob() can go further since string segment made up by triplets mentioned before can be created by only one atob(), which is shorter by three-by-three conversion. additionally, some triplets are impractical with atob() as triplet, but their corresponding base64 string have code shorter than original triplet, hence can be combined into single atob() with suitable context. For example, "://" (common in URL header) currently costs 1311 chars, which base64 string "Oi8v" only costs 723 chars, but atob("Oi8v") costs 1544 chars. Such usage of batch atob() conversion would be challenging since you need an algorithm to clip out most suitable segment form original string for batch atob() conversion.

fasttime commented 1 year ago

"mCh" is useful to optimize "fromCharCode" which is found in many definitions. Providing definitions for every sequence of characters that could be possibly optimized with atob is not an option. I started working on a generic algorithm to optimize arbitrary sequences using different native functions, but in order to implement this feature, many parts of JScrewIt need to be rewritten, so I am thinking to do this in a next major version, without support for certain old engines.