Obfuscated vs Non-Obfuscated JavaScript: Visual Comparison

Someone recently said that obfuscated plugins reduce game performance. I kind of handwavely dismissed their concern, because how bad could it possibly be? Terrible, it turns out.

I obfuscated a map editor thing I'm prototyping, and it became unbearably slow.

This is the project loading process with obfuscation:

obfuscated1.gif


This is the normal, non-obfuscated project loading process:

normal1.gif


Here's what happens when using the ellipse tool to draw on a 256x256 map, obfuscated:

obfuscated2.gif


Here's the normal, non-obfuscated version:

normal2.gif


Obfuscation turns code into spaghetti slop. Even the JavaScript engine has a hard time understanding it, so it can't optimize it. Surely there must be a better way to protect the code? A way that doesn't involve forcing users to experience excruciating slowness?
obfuscating doesn't be a bad thing, IF and only IF you use the correct one
that is NWJS compatible one with it.

another thing that I have with one of my plugin is that the console log
stop works like: console.log(1+1) => output undefined instead of 2.

some functions can block it while obfuscating while unobfuscated works,
but it doesn't reduce performance persé.

it depends how its made and how it obfuscated in some of the programs.

obfuscator.io is a nwjs compatible one, but it should always be tested if it works.
arthran (you alive, buddy?) did a pretty in depth test of obfuscations effects, seen in this thread:
Thread 'Obfuscated Plugins - Something you should be aware of.'

He and I also partnered up to run even more in depth testing with a more refined test set up, but sadly we (mostly me 😅) never got around to publishing the results.

The main take away should be that obfuscations does have an impact, but to what degree depends on how much obfuscation is applied (you can apply it to varying degrees of intensity) and to what exactly is being run.

As far as protecting plugins, there aren't really any good solutions publicly available for RM.
@AceOfAces_Mod has his cook tool, but only works with some plugins.

It's also worth defining intent. Since obfuscation's intent is to prevent copying of protected code, but it doesn't prevent re-use of the plugin.
Plugin protection (like the limited amount provided by cook tool) is more to prevent people from ripping the plugin from a game to use as their own.
Surely there must be a better way to protect the code? A way that doesn't involve forcing users to experience excruciating slowness?
A plugin developer must still test the performance of their code, and for those who don't know: We have a powerful performance measurement tool: the dev console (F12 while in testplay). In case you identify a bottleneck due to your obfuscation, then you must change or remove your obfuscation mechanism, otherwise, you can keep it as it is.
Yes, the performance impact of obfuscation is one of the reasons I believe Yanfly suite to be better than VisuStella suite. It's not a made up reason. The others are it's a lot cheaper, you or others can tweak the code to your use case, and you are not at the mercy of the devs for support and maintenance.
Another obfuscation nuisance is it can be a bit of a pain when, for instance, you are trying to look at other people's plugins to work out how to do MZ plugin commands so your plugins don't need FOSSIL to work in MZ.:blush:
Surely there must be a better way to protect the code?
yes.
patent it and upload it to a storage server, with the license that says "this is mine".

or,... code in assembler.

neither of those is free.
some functions can block it while obfuscating while unobfuscated works,
but it doesn't reduce performance persé.

This is from obfuscator.io:

obfuscation_vm.jpg


That's throwing away most of the performance Google squeezed out of V8.

The main take away should be that obfuscations does have an impact, but to what degree depends on how much obfuscation is applied (you can apply it to varying degrees of intensity) and to what exactly is being run.

Yes. Normal UI interaction wasn't perceptibly affected, but hot paths like shape drawing were. The underlying JavaScript engine would normally optimize these hot paths, but the obfuscation turned the code into a giant spaghetti maze.

In case you identify a bottleneck due to your obfuscation, then you must change or remove your obfuscation mechanism, otherwise, you can keep it as it is.

That's the thing though: it's death by a thousand cuts. Everything gets slower, some code paths more than others.

yes.
patent it and upload it to a storage server, with the license that says "this is mine".

or,... code in assembler.

neither of those is free.

Don't take it personally, but that's a pretty unhelpful answer, for multiple reasons.

As an individual, I'm not interested in doing free Research and Development for companies, so I'd like some things to remain hidden or "obfuscated" because their value lies in the novelty of the idea or in the technical execution of the idea. In these cases, the license is useless.

I'm also not interested in getting my code analyzed and ingested by AI companies. Patents and licenses don't prevent unscrupulous usage of the code. If someone takes your code and converts it to a language that can be compiled to x86 executables, how are you going to check that they're infringing your patent or your license?

Coding in assembly isn't even necessary, by the way. I can code in a higher level language and let a compiler do the conversion, depending on my target architecture.
A game is not only plugins; it's a stack of Node, PIXI, and the RPG Maker's code itself. Well, I don't have the numbers but let's assume the performance breaks down like this:

1768139639549.png


What's the point when a single plugin runs slightly slower, given that every RPG Maker's game window, event, the player themselves, and many more objects are updated 60 times a second?
What's the point when a single plugin runs slightly slower, given that every RPG Maker's game window, event, the player themselves, and many more objects are updated 60 times a second?

You appear to be holding the position that the performance loss caused by obfuscation doesn't matter. I started the thread showing a case where it really does matter, and asked for alternative ways to protect the code.

We're not discussing hypotheticals. I'm interested in knowing what others use or do when obfuscation would be unacceptable due to the performance loss caused by it.
I think the main point me and Arthran wanted to present was more along the lines:
Obfuscation isn't something you should worry too much about, but it's impacts are something you should be aware of.

What tangled up our second round of testing and prevented it from ever being published was more a concern of whether the consumer of the code should be aware of this fact when purchasing any plugin, or whether a seller of plugin's responsibility is to inform their customer of obfuscation (or both).

Regardless, Arthran nor I were ever arguing that obfuscation is a performance obliterater.
For shigs and gigs we ran the entire RPG core through an obfuscator to check it's performance and while there was a noticeable impact for sure, it didn't handicap the game to unplayable states.

Now that I am replying to this on my PC and not my phone, let me dig up some of the charts I made...

graph-EventCalls.png


I don't want to write a whole college thesis, so I'm just going to briefly explain the testing methodology - and excuse me, it's been a few years since we ran these tests, so my memory is a bit fuzzy.

The bench mark made by @Arthran ( 😢please respond buddy! We miss you!) would run 4 scenes, and continually run/spawn/call them until frame rate dropped below 60fps for greater than 60 seconds. This was developed in MZ, by the way. We used free and non-obfuscated plugins and ran them through an obfuscator with conservative levels of obfuscation.

I ran the benchmarks and plotted the data. Each scene was ran 10 times to average out any run-to-run variance, reducing margin of error.

The 4 scenes can be seen in the graph above.
The graphics/audio calls would spawn animations continually until the target limit was hit.
Sprite calls would spawn sprites until the target limit was hit.
Pathing calls would make random path finding requests until the target limit was hit.
Logic calls would do math operations until the target limit was hit.

And then the shigs and gigs graph:
Run-to-run Variation.png


Total obfuscation being the entire engine being obfuscated. "Straight" being no obfuscation at all.

Among the data collected was also hardware utilization, as well as the individual per-run utilization for each scene.
For example here is one of all 10 runs:

Math Calls.png


Thank you for coming to my TED talk, and I apologize for never publishing this data 😐 Forgive me of my sins.

edit:
ah, and one thing I think I did during these tests that I forgot to mention was to run the test 11 times, but remove the very first test. This is often because the first test performance would not be representative due to things being moved into memory or other technical processes the computer runs on first boot.
Thank you for coming to my TED talk, and I apologize for never publishing this data 😐 Forgive me of my sins.

That was an incredibly valuable post. Thank you so much for writing it!

Now that we likely all agree that obfuscation does have an impact and that in most cases it doesn't matter that much, can we discuss what the available options are for the cases where it does matter?

I know that not protecting the affected part of the code is an option, but I'd like to know if there are viable options to both protect the code and maintain as much performance as possible.
You appear to be holding the position that the performance loss caused by obfuscation doesn't matter. I started the thread showing a case where it really does matter, and asked for alternative ways to protect the code.

We're not discussing hypotheticals. I'm interested in knowing what others use or do when obfuscation would be unacceptable due to the performance loss caused by it.
I honestly don't want to come off as stubborn or disrupt the discussion; sorry if it came off that way. I think I'm just a bit puzzled because your example from the original post is from a map editor and not a running game, which is not the same.
I think that the bigger the plugin is, the more it can impact.

as small plugins and obfuscating doesn't have much impact.

but if you want to protect your code, maybe do some portions out of it.
not entirely, like total complex drawing normal, ready those obfuscated.

PKD does some parts of his code obfuscated too.

but I didn't know it could impact that much as the thread from athran
made it with visustella, that by normal use, it doesn't have a super impact
unless by extreme or use it incorrectly where it can fall huge.

but for what I obfuscate, there isn't a big impact or slow downs.
but I do see that it can be a big issue.
Hello, I'm totally unexperienced in obfuscation and in JS, but maybe you can observe which obfuscation technique slows your code significantly and opt for other techniques?
Like I suppose adding too many lines code jump in the source file might decrease js interpreter performances.
If you really don't want to have some parts of your code in clear, maybe write them in another langage that could be compiled to make it pay some part of the obfuscation cost while still being efficient?
their value lies in the novelty of the idea or in the technical execution of the idea
economics might disagree.

In these cases, the license is useless.
not if it's sustainable in court.

Original thread: https://forums.rpgmakerweb.com/threads/obfuscated-vs-non-obfuscated-javascript-visual-comparison.181876/