将String解析成JSONObject这个场景,fastjson2表现没有两倍于fastjson1的性能[QUESTION]
chxuan opened this issue · comments
chxuan commented
Shaojin Wen commented
你跑下这个类的main方法,我刚测试的结果:
Benchmark Mode Cnt Score Error Units
EishayParseTreeStringPretty.fastjson1 thrpt 5 647.006 ± 7.090 ops/ms
EishayParseTreeStringPretty.fastjson2 thrpt 5 1093.328 ± 7.012 ops/ms
EishayParseTreeStringPretty.jackson thrpt 5 708.005 ± 1.783 ops/ms
Shaojin Wen commented
结果类似,这个场景都是快60%多一些
chxuan commented
@wenshao 温少,如果测试json里面还有嵌套json字符串,在进行解析的时候会反转义,那么fastjson2相较于fastjson的性能提升就更不明显了(提升百分之几到百分之二十),如果json字符串更大(比如10k+)fastjson2还要比fastjson慢百分之几到百分之三十左右,我目前使用fastjson的场景是解析json日志(日志场景特点:1.json字符串较大,3k左右;2.日志里面会有大量转义字符)
Shaojin Wen commented
如果方便提供脱敏后的样本数据给我,我做下性能验证。我的邮箱 shaojin.wensj(at)alibaba-inc.com
chxuan commented
@wenshao 温少,邮箱格式不正确吗?邮件发不了,json测试样例子:https://github.com/chxuan/test/blob/master/test.json
chxuan commented
我这边的测试结果是fastjson2的性能略低于fastjson
Shaojin Wen commented
Benchmark Mode Cnt Score Error Units
Issue206ParseTreeStringPretty.fastjson1 thrpt 5 105.304 ± 0.815 ops/ms
Issue206ParseTreeStringPretty.fastjson2 thrpt 5 105.256 ± 0.474 ops/ms
Issue206ParseTreeStringPretty.jackson thrpt 5 103.431 ± 1.330 ops/ms
看这个测试代码,用jmh测试,都差不多,主要是其中message转义会导致较慢。我本地环境fastjson2还是略快一点点,我后续会看下怎么优化你这个场景。
Shaojin Wen commented
@chxuan 做了一些优化,已经能比fastjson 1.x快大约30%,你用上面链接的2.0.3-SNAPSHOT版本试试看
下面是我在zulu JDK 8下的测试数据
Benchmark Mode Cnt Score Error Units
Issue206ParseTreeStringPretty.fastjson1 thrpt 5 97.443 ± 0.364 ops/ms
Issue206ParseTreeStringPretty.fastjson2 thrpt 5 130.543 ± 0.859 ops/ms
Issue206ParseTreeStringPretty.jackson thrpt 5 95.572 ± 2.637 ops/ms
zulu JDK 11的测试数据
Benchmark Mode Cnt Score Error Units
Issue206ParseTreeStringPretty.fastjson1 thrpt 5 74.009 ± 0.226 ops/ms
Issue206ParseTreeStringPretty.fastjson2 thrpt 5 118.881 ± 2.171 ops/ms