Performance: Is it needed to put JSON object one by one to a new class?

I am working on Android project that manipulate a big JSON Objects with many types..

In performance point of view, is it needed to put the JSON object one by one to another class?

For example I have:

    {
      "status":"ready",
      "date":"2014-04-11T00:32:19Z",
      "number":208,
      "id":521,
      "links":"/tracks/somewhat.mp3",
      "title":"why-is-black",
      "sub_title":"Birdy",
      "tags":[
              "bugs",
              "rat",
              "flower"]
    }

I have around 1000 of JSON object like that.. Is it effective to create a new object every time the apps loads?

   Tracks tracks = new Tracks(status,date,number,id,links,title,sub_title,tags);

in this app i will manipulate the data frequently..

In my mind i have two solution 1. Create a new object for every JSON Object 2. Save everything as a string and manipulate within the JSON itself..

or do you guys recommend anything else? Thanks a lot!

Jon Skeet
people
quotationmark

Creating 1000 objects is peanuts. It should be absolutely fine, even on a mobile device. Create the objects when you read the JSON, manipulate them (as objects) within your app, and then write them out as JSON again when you need to.

Manipulating JSON directly is likely to be much more hairy - it'll be hard to get right and may well perform worse. Whenever you think "Maybe I'll just use string manipulation instead of treating these objects as, you know, objects" you should really have a very good reason to do so, with decent evidence.

As ever, a good approach to performance is:

  • Determine what will be acceptable performance
  • Write your code in the cleanest, simplest way possible
  • Measure whether the performance is good enough
  • If it's not, work out (via profiling or whatever) where the performance bottlenecks are, and try to address them without losing too much code cleanliness.
  • Repeat until you have an app which performs well enough without being too hard to maintain.

Micro-optimizations are easy to add later if you need them (and usually you don't). Architectural optimizations (working out when one system needs to interact with another) is generally much harder to do later, so it's a good idea to prototype and measure that side of things as early as possible.

people

See more on this question at Stackoverflow