简体   繁体   English

如何使JSON Jackson更快?

[英]How to make json jackson faster?

this line of code takes about 2 seconds to execute! 这行代码大约需要2秒钟才能执行!

ObjectMapper mapper = new ObjectMapper();

since two seconds is a life time when it comes to computing, is there any way to make jackson respond faster? 由于两秒钟是计算的生命周期,有什么方法可以使杰克逊更快地做出响应?

i am using : 我在用 :

    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.13</version>
    </dependency>

The version of Jackson you are using is an older version, consider upgrading to Jackson 2.0. 您正在使用的Jackson版本是较旧的版本,请考虑升级到Jackson 2.0。 There may be a bit of efforts involved (depends on what APIs you are using), but any new features and performance enhancements will likely to be 2.x only. 可能需要付出一些努力(取决于您所使用的API),但是任何新功能和性能增强都可能仅是2.x。 Have a look at Jackson Release: 2.0 for more information and upgrade notes. 请查看Jackson版本:2.0,以获取更多信息和升级说明。

As for ObjectMapper , this is what Jackson Best Practices: Performance says: 对于ObjectMapper ,这就是Jackson最佳实践:性能所说的:

ObjectMapper : object mappers cache serializers and deserializers that are created first time handler is needed for given type (or more precisely, mapper holds a reference to Provider objects that do). ObjectMapper :对象映射器缓存第一次为给定类型的处理程序创建的序列化器和反序列化器(或更确切地说,映射器持有对提供者的引用)。 If you do not reuse mappers, new serializers and deserializers need to be created each time: and these are expensive operations due to amount of introspection and annotation processing involved. 如果不重用映射器,则每次都需要创建新的序列化器和反序列化器:由于涉及内省和注释处理的数量,因此这些操作很昂贵。

What is the platform you are running on, mobile perhaps? 您正在运行的平台是什么(移动平台)? On my 3+ year old laptop creating an instance takes less than half a second. 在我3岁以上的笔记本电脑上,创建实例所需的时间不到半秒钟。

If performance is a concern and your JSON is not too complex, consider using Jackson's streaming API (that's the real power of Jackson) to parse the JSON data yourself, it will be an order of magnitude faster. 如果需要考虑性能,并且您的JSON不太复杂,请考虑使用Jackson的流API(这是Jackson的真正功能)自己解析JSON数据,它将快一个数量级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM