.Json VS .JS read and execute time...?

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
484
Reaction score
288
First Language
Portuguese(BR)
Primarily Uses
RMMV
One question that came to mind some time ago was: What is read and executed faster, inside Nwjs/NodeJS/V8: Json or JS files?

Because while they may seem the same, Javascript can take around 2 seconds to read, parse and be executed as you can see in that image(1MB .js file) :

on the other hand, I don't know how MV's engine deals with .json files, so I don't know how they compare to javascript.



So which one is faster in the end?
 
Last edited:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,440
First Language
French
Primarily Uses
RMMV
One question that came to mind some time ago was: What is read and executed faster, inside Nwjs/NodeJS/V8: Json or JS files?

Because while they may seem the same, Javascript can take around 2 seconds to read, parse and be executed as you can see in that image(1MB .js file) :

on the other hand, I don't know how MV's engine deals with .json files, so I don't know how they compare to javascript.



So which one is faster in the end?
that's why the pixi loader exists. and PIXI.utils for cache all what you need.
Logic want you to compile all during the loading phase of your game.
In test I charge for more than 200 MB of json from spine data.
And no worries.
Add a extra second or 2, to loading time, are really not catastrophic.
It much more important than accessing objects in real time.

and yes , i sugest you to remove all stuff from rmmv.
And also make only one big file.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
You know, it's pointless to ask this question. Here's why:
What's a JS file?
A normal text file with UTF-8 encoding.
What's a JSON file?
A normal text file with UTF-8 encoding.
What loads, parses and executes JS files?
JS interpreter.
What loads, parses and executes JSON files?
JS interpreter.
So what is the difference between JS and JSON files?
The difference is that one is a JS file and the other is JSON.
Any other difference?
Absolutely none.
So why should JSON files load or be executed any faster than JS files?

It's completely natural for mobiles to deal with JS files slowly. They have less single core processing power, because they rely on multicores, and less powerful engines, because they need to conserve space.
 

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
484
Reaction score
288
First Language
Portuguese(BR)
Primarily Uses
RMMV
So why should JSON files load or be executed any faster than JS files?
JS files requires load, parse, compile and execute, but for Json, it's just read and execute, because there's no code in it(At least I think), what may make it faster.


So if we take information out of JS and put it in Json, that maybe can improve performance and loading speeds a little, making it better and better the more complex(and therefore, more JS files) the project has.
Also Json can be "encrypted" using base64 to reduce size. So in the end, moving that information to Json and encrypting can make the whole thing better.

that's why the pixi loader exists. and PIXI.utils for cache all what you need.
Logic want you to compile all during the loading phase of your game.
In test I charge for more than 200 MB of json from spine data.
And no worries.
Add a extra second or 2, to loading time, are really not catastrophic.
It much more important than accessing objects in real time.

and yes , i sugest you to remove all stuff from rmmv.
And also make only one big file.
It's not only about loading. Js code is executed line by line because of it's JIT nature(as far as I know), so the less lines, less compilation time, faster to execute the code.
Also, taking out parameters of the .js files of plugins, we can use tools such as JSCompress to reduce it's size and improve it.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
Alright, let me teach you a little bit about how an interpreted language works.
The reason why you don't need to compile your scripts into a program is, because the interpreter interprets the code and compiles it into machine code. The difference between a compiled and an interpreted language is, compiled language needs precompiled machine code and uses a decompiler to read the machine code.
Interpreter takes a script and generates machine code on the runtime. Which saves loading speeds, because it's on runtime. And as a bonus it takes dynamically generated code.
The reason why JSON files don't get compiled is because JSON files are usually used as DATA stores. And data doesn't need any compilation, you only load it into RAM. That is why JS and JSON files have been diversified in the first place.
But it's impossible to say that you'll cut code from JS and put it into JSON. Because in order for that code to even be executable, the interpreter has to interpret it, in other words it has to convert it to machine code.
Also, thanks to the ability of JS interpreter to run dynamically generated code you can encrypt even JS files. In fact I've already told you this over PM.

And as a side note, any encryption or compression you make increases the loading and execution time, because before you can even use the file, you have to decompress or decrypt it to a readable structure.
 
Last edited:

peq42_

Yeet
Veteran
Joined
Feb 5, 2016
Messages
484
Reaction score
288
First Language
Portuguese(BR)
Primarily Uses
RMMV
But it's impossible to say that you'll cut code from JS and put it into JSON. Because in order for that code to even be executable, the interpreter has to interpret it, in other words it has to convert it to machine code.
Also, thanks to the ability of JS interpreter to run dynamically generated code you can encrypt even JS files. In fact I've already told you this over PM.
I probably was not clear about what I thought about putting in a .json file.
What I think about moving to .json files are those instructions that most plugins have before the code itself(example in that image), which are there to make configuring plugins a easier task. My idea is to move that to a .json file, for its work is to store data to be read/saved and only that.

If I encrypt or use that JSCompress in a plugin, it loses that easy way to configure the plugin, because all parameters listed in that first part (which are comments) are removed, among with spaces and other stuff.

I'm probably not being all that clear today because my thoughts are a bit slow. I'm really tired and I think i'm getting sick.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,640
First Language
Czech
Primarily Uses
RMMV
There's no point in doing that. Because:
1. they are there exactly only for RPG maker, meaning if you remove them from the scripts, RPG maker won't be able to use them anyway.
2. The interpreter ignores comments, meaning you only lose time you spend loading the commented stuff. Which is the same in both JS and JSON, because the same loader handles them.
3. For already deployed games this is just an useless chunk of data, so rather than saving them inside a JSON file you can delete them altogether. All parameters are saved inside plugins.js, so you're not losing on anything.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top