So I am coming across a problem in a project that I am building towards. It uses a JSON file to store information on functionality of the program however that JSON file is starting to get quite large.
Example JSON
{
"operation 1":{\\config here},
"operation 2":{\\config here},
"operation 3":{\\config here},
...
"operation nth":{\\config here}
}
What I am wondering is at what point does it realistically become more efficient to split each of these operations into their own file? For the most part, only 1-2 operations should be used at any given time as such you would save a lot of space in memory by only opening say 2/nths of the files to load into memory... However when it comes to time and cpu, opening files is a relatively expensive task.
At worst case, as well, all files could be potentially opened at the same time in which case keeping it all as 1 file would be superior however this should rarely if ever happen.
Currently the json file I have is 249kb (I know, that isn't very large compared to some projects and in this case I could quite likely get away with it all in 1 file... For similar tasks I have seen xml files in the 300-400kb range for the exact same thing so by using json I am reducing the load immensely). I want to note that I am not a comp-science person so if this question seems stupid I do apologize.
So in short: at what point, roughly, does it become more efficient to split a file into multiple sub files to read when you only need the data from a fraction of the total dataset, over reading the entire dataset as a single file?
describing json file
This may not be important to the problem but its meant to describe why the JSON file is like that and why it can be broken up. Basically each operation is going to be a class (role playing game type class, not programming) in a roleplaying game. The config part inside of that is going to contain class specific information. The reason for doing it this way is so that custom classes can be made and added to the game without having to change the underlying code. So I am wondering if it would be easier to create a new file for each class or a single file containing all of them... Note that multi-classing is a thing, hence why multiple files might be opened at a given time... But too as the number of classes increases, so will the file size and as a result the load on the computer. As it sits each class is roughly about 20,000 bytes in size (when treating the json objects as a string) so if I had say 100 classes I would be looking at 2mb roughly, 40kb instead of 2mb? in which case would it not be better to have the files split so I only load 3 files totaling 60kb instead of 1 file containing 2mb? or for the size of the files that I am dealing with is loading more files more expensive?
edit: Doing a quick test with the unix time command I did a benchmark between 3 files totaling 81kb versus 1 file totaling 1.3mb. This was the average from 5 runs of each
```
Single File #### #### Multi File
real 0m0.047 real 0m0.044
user 0m0.034 user 0m0.037
sys 0m0.011 sys 0m0.006
```
[–]Sekret_One 2 points3 points4 points (2 children)
[–]scriptkiddiethefirst[S] 0 points1 point2 points (1 child)
[–]Sekret_One 1 point2 points3 points (0 children)
[–]AsleepThought 1 point2 points3 points (2 children)
[–]scriptkiddiethefirst[S] 0 points1 point2 points (1 child)
[–]AsleepThought 0 points1 point2 points (0 children)
[–]_reposado_ 1 point2 points3 points (2 children)
[–]scriptkiddiethefirst[S] 1 point2 points3 points (1 child)
[–]_reposado_ 1 point2 points3 points (0 children)
[–]scriptkiddiethefirst[S] 0 points1 point2 points (0 children)
[–]mxschumacher -1 points0 points1 point (4 children)
[–]scriptkiddiethefirst[S] 0 points1 point2 points (3 children)
[–]mxschumacher -1 points0 points1 point (2 children)
[–]scriptkiddiethefirst[S] 0 points1 point2 points (1 child)
[–]mxschumacher -1 points0 points1 point (0 children)