Theory: Compacting strings reduces size?

9 views
Skip to first unread message

Kevin "Ingwie Phoenix" Ingwersen

unread,
Mar 4, 2016, 10:28:04 PM3/4/16
to nod...@googlegroups.com
Hey folks!

While thinking about how I could better optimize my code than just with my coding style, and tools, I came across the SMAZ algo, and that got me thinking. Because there is a module named keysquash that picks up commonly used keynames in a code, and wraps it in a function, to reduce the amount of code when being compressed. I wonder if this is possible for strings, too.

Commonly, a script may contain a lot of event names, such as "error", "data" or in a browser: "click". So would it theoretically be possible to save bytes, by replacing them?

For instance, if we had (I know, really small. Try to imagine a bigger chunk):


SomeElementNames.forEach((name)=>{
document.getElementById(name).addEventListener("click", function(){})
})


Would replacing it into something like

((x)=>{
SomeElementNames.forEach((name)=>{
document.getElementById(name).addEventListener(x.a, function(){})
})
})({a:"click"})

actually help?

I was thinking of what would happen if we also added SMAZ here and a simple decompressor. But that may depend on the scene…

What do you guys think?

Kind regards,
Ingwie
Reply all
Reply to author
Forward
0 new messages