java - 为什么这个 JSON Parsing 越来越高效了?

标签 java android json caching jsonparser

我有一个在 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 虚拟机)应用程序中都很常见。

关于java - 为什么这个 JSON Parsing 越来越高效了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56901567/

相关文章:

php - 使用jquery解析php发送的json

javascript - Laravel 将 json 传递给 vue.js

java - youtube api 显示 channel 视频 android

java连接方法

android - Android 上的屏幕键盘不会为第二语言发送正确的键码

python - 需要身份验证 - 使用 Python 建立 AIM OSCAR session 时出现问题

java - 最佳实践 : Input Validation (Android)

Java Spring Boot 异常处理

android - 从 DataStore 读取一次值以更新 fragment 中的选项菜单复选框状态

android - GCM 中的注册应用程序问题