Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to resolve Fastjson and Jackson performance problems

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to parse the performance of Fastjson and Jackson, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following for you. I hope you can get something according to this article.

Previously, this article will not compare the json parsing performance of fastjson and Jackson in normal business scenarios, but will focus on comparing their performance in parsing large json strings. It can be concluded that the performance of jackson is better than that of fastjson in parsing large json scenarios, there is no hurry, we have the picture and the truth.

My definition of a large Json is that a json string larger than 1m in size can be considered a big json. You may not encounter json strings with a size of more than 1m, only a few hundred kb at most, and the parsing performance of this level of json,fastjson and jackson can be compared with some analysis articles on the net.

The big Json parsing scenario I encountered came from calls to third-party interfaces. The largest is a 64m json string, which is output to a text file and calculated based on the size of the file. Some third-party interfaces don't have paging capabilities. I came across an interface call that returned millions of pieces of data at a time, and it was from that time that I discovered the disadvantages of fastjson.

As previously tested, it took more than an hour for 64m json to parse with fastjson. In this scenario, fastjson is no longer fast. Today, I'm testing a json string parsing with only 2000 records, using fastjson and jackson, respectively, to compare the performance of the two.

As you can see from the test code, this is a time-consuming example of calling a third-party interface, getting the response body, and then parsing using fastjson and jackson tests, respectively.

Method output:

As you can see, jackson parsing takes only 318ms, while fastjson takes 641459 milliseconds, which is not the slightest difference, a full 2017 times. And the longer the json string, the greater the performance difference. You can test it yourself and simulate a string with a size of more than 1m, using fastjson and jackson respectively.

In fact, Fastjson also provides a solution for this large json parsing scenario, stream api, but it does not solve most business scenarios. If you are interested, you can study it.

You may want to solve this problem by shortening Json strings, and indeed, who would be so boring? setting an interface that responds to such a large amount of data is simply a database copy. It is true that this can be solved by supporting paging through the interface, but you can't get others to change the design. The interface is someone else's, and the only thing we can do is to optimize it ourselves.

After reading the above, do you have any further understanding of how to parse Fastjson and Jackson performance issues? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report