Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am currently working on a small project in which I work with some \"static dat

ID: 646294 • Letter: I

Question

I am currently working on a small project in which I work with some "static data", which is extracted from one source. The data might change from time to time (up to once a week). I don't need all of the information the data includes in my project so to allow easier and a more logical access to it I wrote some small tool that converts the extracted data into my desired format.

The conversion is mostly dropping data I don't need, and splitting some strings into arrays. No intensive calculations or anything. But, I drop more than 50% of the original data because their is no need for it.

Now since it is static data would it make more sense to just store that converted data and do all further operations from this data or would it make more sense to convert from the raw data on the fly?

Since the project is in JavaScript speed of course is important, but if converting on the fly has significant advantages it might make more sense to go with that approach.

It is static data from a computer game that defines several units and other objects within the game. They are stored in JSON therefore I can easily use them in JavaScript. But I don't need a lot of the information, just some parts of it to build a kind of "encyclopedia", now since the data is already present in JSON I was wondering if I should just use it or convert it before usage.

Explanation / Answer

Generally speaking, duplication is a greater evil than bad performance. The answer will typically depend on whether the performance is good enough with the on-the-fly conversion. You will have to figure that part out yourself. Stick to the current implementation until you have proof that it's too slow; do not optimise it because you guess that it will be too slow.

An alternative approach would be to take your on-the-fly code, and create a pre-processor out of it, which outputs the cut-down data set. You can then run this code as part of your build process. The benefit is that your core data set is not (really) duplicated, and you get the performance benefits. Also, I realise that this code is in JavaScript, but there are ways to get JS to run on your development machine during the "build".