Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize wrapper #108

Merged
merged 1 commit into from
Sep 2, 2020
Merged

Optimize wrapper #108

merged 1 commit into from
Sep 2, 2020

Conversation

hazzik
Copy link
Contributor

@hazzik hazzik commented Sep 2, 2020

Optimize wrapper based on #107 (comment).

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
Copy link
Contributor Author

hazzik commented Sep 2, 2020

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

@aemkei aemkei merged commit 1f3cf30 into aemkei:master Sep 2, 2020
@aemkei
Copy link
Owner

aemkei commented Sep 2, 2020

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

@aemkei
Copy link
Owner

aemkei commented Sep 2, 2020

Also deployed this version to jsfuck.com.

@hazzik hazzik deleted the optimize-wrapper branch September 2, 2020 08:28
@hazzik
Copy link
Contributor Author

hazzik commented Sep 2, 2020

Thanks!

@kamil-kielczewski
Copy link
Contributor

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants