Why is this JSON Parsing becoming more and more efficient?

ColonD :

I have a function to parse JSON in android. I use org.json for my parsing.

It is something like this:

class ClassName {

public static ArrayList<DataObjectClass> parseResponse(String response){

    JSONObject responseObject = new JSONObject(response);
    if(responseObject.has("someArray")){
        JSONArray someArray = responseObject.getJSONArray("someArray");
        // etc... etc... and i do logic
        }
    }
    return new DataObjectClass(params...)
}

Now I timed my parsing from start to end, and each time I call the function again the parsing time reduces (Unless i quit the app and come again)

I checked the JSONTokener Code and JSONObject code, but I cant find any code for caching. Where is this happening and how can I turn it off (for testing purposes)

TheKarlo95 :

It might have something to do with how ART(Andorid RunTime) runs the code.

From docs:

Android runtime (ART) includes a just-in-time (JIT) compiler with code profiling that continually improves the performance of Android applications as they run. The JIT compiler complements ART's current ahead-of-time (AOT) compiler and improves runtime performance, saves storage space, and speeds application and system updates. It also improves upon the AOT compiler by avoiding system slowdown during automatic application updates or recompilation of applications during over-the-air (OTA) updates.

Although JIT and AOT use the same compiler with a similar set of optimizations, the generated code might not be identical. JIT makes use of runtime type information, can do better inlining, and makes on stack replacement (OSR) compilation possible, all of which generates slightly different code.

This means that each time ART runs you code it will analyze how it run and how it can improve that. When you quit your app all that data is lost and it starts again. This is common in all JVM(Java Virtual Machine) applications.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=127482&siteId=1