为什么这个 JSON 解析越来越高效了?
Why is this JSON Parsing becoming more and more efficient?
我有一个函数可以在 android 中解析 JSON
。我使用 org.json
进行解析。
是这样的:
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...)
}
现在我从头到尾计时我的解析,每次我再次调用该函数时解析时间都会减少(除非我退出应用程序然后再来)
我检查了 JSONTokener
代码和 JSONObject
代码,但找不到任何缓存代码。这是在哪里发生的,我该如何关闭它(用于测试目的)
这可能与 ART(Andorid RunTime) 运行 代码的方式有关。
来自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.
这意味着每次 ART 运行 编写代码时,它都会分析它 运行 的方式以及它如何改进它。当您退出您的应用程序时,所有数据都会丢失并重新启动。这在所有 JVM(Java 虚拟机)应用程序中都很常见。
Why is this JSON Parsing becoming more and more efficient?
这就是 及时 编译器所做的事情。
他们了解(通过某种分析,或者有时:简单地计算方法调用)代码的哪些部分对性能至关重要。在某个时候,他们进来,并将 java 字节码翻译成例如本机机器代码。
换句话说:最有可能的是,当您的代码执行某些操作时 "just often enough",JIT 会在某个时候(可能会分多个步骤逐步)将其重新编译为越来越优化的(机器代码)表示形式。
我有一个函数可以在 android 中解析 JSON
。我使用 org.json
进行解析。
是这样的:
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...)
}
现在我从头到尾计时我的解析,每次我再次调用该函数时解析时间都会减少(除非我退出应用程序然后再来)
我检查了 JSONTokener
代码和 JSONObject
代码,但找不到任何缓存代码。这是在哪里发生的,我该如何关闭它(用于测试目的)
这可能与 ART(Andorid RunTime) 运行 代码的方式有关。
来自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.
这意味着每次 ART 运行 编写代码时,它都会分析它 运行 的方式以及它如何改进它。当您退出您的应用程序时,所有数据都会丢失并重新启动。这在所有 JVM(Java 虚拟机)应用程序中都很常见。
Why is this JSON Parsing becoming more and more efficient?
这就是 及时 编译器所做的事情。
他们了解(通过某种分析,或者有时:简单地计算方法调用)代码的哪些部分对性能至关重要。在某个时候,他们进来,并将 java 字节码翻译成例如本机机器代码。
换句话说:最有可能的是,当您的代码执行某些操作时 "just often enough",JIT 会在某个时候(可能会分多个步骤逐步)将其重新编译为越来越优化的(机器代码)表示形式。