aemkei / jsfuck

Write any JavaScript with 6 Characters: []()!+
jsfuck.com
Do What The F*ck You Want To Public License
8.07k stars 671 forks source link

Optimize wrapper #108

Closed hazzik closed 3 years ago

hazzik commented 3 years ago

Optimize wrapper based on https://github.com/aemkei/jsfuck/pull/107#issuecomment-684646669.

Replace \ in escape character with t (cheapest symbol outside of base 16 numbers) on compile stage. On runtime stage replace t back with \ before passing the string into the Function constructor. To avoid using replace(x,y) function which requires 2 arguments use split() and join() functions.

The "cost" of additional characters is about ~100.

Without this optimization one unmapped caracter has encoded length of about 3600 characters. Every additional unmapped character adds 2000 to the total length.

For example, the length of ~ is 3605, ~~ is 5600, and ~~~ is 7595.

The loader with replace has encoded length of about 5300 characters and every additional character adds 100 to the total length.

In the same example the length of ~~ becomes 5371 and ~~~ -- 5463.

So, when we have more than one unmapped character we want to encode whole input except select characters (that have encoded length less than about 70) into an escape sequence.

hazzik commented 3 years ago

Btw, the length of JSFuck-encoded jsfuck.js is reduced from 4,711,510 characters to 487,754 characters (10 times!)

aemkei commented 3 years ago

Well, this is a great improvement! Many thanks for taking the time @hazzik !

aemkei commented 3 years ago

Also deployed this version to jsfuck.com.

hazzik commented 3 years ago

Thanks!

kamil-kielczewski commented 3 years ago

@hazzik I was curious how big code of jsfuck.js create small-jsfuck and it creates 258kb of code - Im surprised that pure jsfuck only ~double this result after your fix-es (!). However it looks like they are not deploye yet