Skip to content

fastjson_benchmark

温绍锦 edited this page Mar 19, 2023 · 37 revisions

更多测试数据看这里 https://github.com/alibaba/fastjson2/tree/main/docs/benchmark

1. 测试环境

1.1 各个库的版本

  • fastjson2 2.0.15
  • fastjson1 1.0.83
  • jackson 2.13.4
  • gson 2.9.1
  • kryo 5.3.0
  • hessian 4.0.66

都是截止测试时间(2022-10-05)各个库的最新版本

1.2 服务器环境

测试的服务器基于阿里云最新代ECS,包括x64架构的Intel和AMD处理器,ARM架构的AltraMax和阿里云平头哥的倚天处理器。

cs.c7a.xlarge
ecs.g8m.xlarge
Orange Pi 5
AppleM1Pro

ecs.c7.xlarge

这个是阿里云当前代标准型ECS,处理器型号 Intel Xeon(Ice Lake) Platinum 8369B,4核,8G内存 image

ecs.g8m.xlarge

这个是阿里云上售卖ARM处理器,处理器型号 Yitian 710,4核,16G内存。这个是阿里云平头哥的倚天710处理器,需要联系客服才能购买。 image

Orange Pi 5

这个是国产的树莓派的高性能替代 http://www.orangepi.org/html/hardWare/computerAndMicrocontrollers/details/Orange-Pi-5.html

image

AppleM1Pro

苹果M1 Pro笔记本电脑,这个是阿里员工的工作用笔记本

1.3 JDK版本

基于Oracle最新版本的Linux x64/aarch64的JDK版本,下载地址 https://www.oracle.com/java/technologies/

  • oracle-jdk1.8.0_371
  • oracle-jdk-11.0.18
  • oracle-jdk-17.0.6
  • graalvm-ce-11-22.3.1
  • graalvm-ce-17-22.3.1
  • graalvm-ee-11-22.3.1
  • graalvm-ee-17-22.3.1
  • zulu-8.68.0.21
  • zulu-11.62.17
  • zulu-17.40.19

1.4 测试代码以及运行方式

git clone https://github.com/alibaba/fastjson2
cd fastjson2
git checkout 2.0.15
mvn clean install -Dmaven.test.skip
~/Install/jdk-1.8.0_361/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/jdk-11.0.18/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/jdk-17.0.6/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/graalvm-ce-java11-22.3.1/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/graalvm-ce-java17-22.3.1/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/graalvm-ee-java11-22.3.1/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay
~/Install/graalvm-ee-java17-22.3.1/bin/java -cp ~/git/fastjson2/benchmark/target/fastjson2-benchmarks.jar com.alibaba.fastjson2.benchmark.eishay.Eishay

2. 测试数据&结果分析

原始数据 https://github.com/alibaba/fastjson2/blob/2.0.15/docs/benchmark/benchmark_2.0.26_raw.md

2.1 EishayParseString

这个是最常用的场景,将JSON格式字符串反序列化为Java对象,这个场景在fastjson中的代码如下:

String str = "...";
Bean bean = JSON.parseJSONObject(str, Bean.class);

这个场景是fastjson1最强的场景;

在ecs.c7.xlarge-jdk1.8.0_361环境中,只相当于只相当于fastjson2的75.97% ;jackson则只相当于fastjson2的40.46%; gson是fastjson2的33.42%,也就是说这个最常见的反序列化场景,fastjson2的性能差不多是jackson/gson的三倍。

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361

      fastjson2 > fastjson1 > jackson > gson
jdk8  100%        75.97%      40.46%    33.42%
jdk11 100%        77.97%      42.76%    35.41%
jdk17 100%        98.30%      38.41%    35.82%

fastjson2在JDK11和JDK8的算法不同,导致这个场景下,fastjson2在JDK8的表现比JDK11下好,JDK17/18/19由于JDK自身性能优化,使得JDK17/18/19性能更好。JDK 18/19比JDK 17性能显著提升。

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 1275.975 969.297 (75.97%) 516.21 (40.46%) 426.44 (33.42%)
ecs.c7.xlarge jdk-11.0.18 1184.086 923.186 (77.97%) 506.262 (42.76%) 419.243 (35.41%)
ecs.c7.xlarge jdk-17.0.6 1289.502 1267.555 (98.3%) 495.332 (38.41%) 461.859 (35.82%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1187.719 1108.73 (93.35%) 510.052 (42.94%) 506.639 (42.66%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1237.734 1435.162 (115.95%) 509.405 (41.16%) 508.993 (41.12%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1498.304 1181.318 (78.84%) 493.889 (32.96%) 482.799 (32.22%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1360.456 1725.838 (126.86%) 494.252 (36.33%) 467.035 (34.33%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 877.338 741.597 (84.53%) 362.676 (41.34%) 346.236 (39.46%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1081.778 741.707 (68.56%) 404.484 (37.39%) 375.704 (34.73%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1093.084 1147.901 (105.01%) 388.002 (35.5%) 363.786 (33.28%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1052.952 812.372 (77.15%) 403.785 (38.35%) 401.184 (38.1%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1089.433 1045.039 (95.93%) 420.843 (38.63%) 395.316 (36.29%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1197.244 960.132 (80.2%) 435.97 (36.41%) 353.493 (29.53%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1151.483 1377.415 (119.62%) 435.793 (37.85%) 416.141 (36.14%)
OrangePi5 jdk1.8.0_361 654.595 560.878 (85.68%) 274.647 (41.96%) 219.88 (33.59%)
OrangePi5 jdk-11.0.18 676.719 577.243 (85.3%) 263.619 (38.96%) 227.293 (33.59%)
OrangePi5 jdk-17.0.6 695.143 809.552 (116.46%) 284.603 (40.94%) 224.739 (32.33%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 665.015 567.59 (85.35%) 277.226 (41.69%) 222.99 (33.53%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 674.736 585.042 (86.71%) 266.435 (39.49%) 227.834 (33.77%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 695.457 806.739 (116%) 281.711 (40.51%) 219.122 (31.51%)
OrangePi5 graalvm-ce-java11-22.3.1 632.079 552.149 (87.35%) 258.34 (40.87%) 239.426 (37.88%)
OrangePi5 graalvm-ce-java17-22.3.1 690.514 715.484 (103.62%) 279.878 (40.53%) 229.838 (33.29%)
OrangePi5 graalvm-ee-java11-22.3.1 776.001 592.693 (76.38%) 266.69 (34.37%) 224.473 (28.93%)
OrangePi5 graalvm-ee-java17-22.3.1 774.152 920.545 (118.91%) 294.38 (38.03%) 243.223 (31.42%)
AppleM1Pro zulu-8.jdk 1800.005 1523.559 (84.64%) 746.68 (41.48%) 656.16 (36.45%)
AppleM1Pro zulu-11.jdk 1876.148 1402.328 (74.75%) 728.383 (38.82%) 734.055 (39.13%)
AppleM1Pro zulu-17.jdk 1943.998 2099.912 (108.02%) 659.946 (33.95%) 708.294 (36.43%)
AppleM1Pro graalvm-ce-java11-22.3.1 1278.928 1174.487 (91.83%) 574.269 (44.9%) 767.595 (60.02%)
AppleM1Pro graalvm-ce-java17-22.3.1 1394.572 1318.848 (94.57%) 578.733 (41.5%) 666.812 (47.81%)
AppleM1Pro graalvm-ee-java11-22.3.1 1337.91 1861.872 (139.16%) 731.325 (54.66%) 718.436 (53.7%)
AppleM1Pro graalvm-ee-java17-22.3.1 1733.339 1797.118 (103.68%) 757.474 (43.7%) 726.256 (41.9%)

2.2 EishayParseStringPretty

这个场景是将格式化过的JSON格式字符串反序列化为Java对象,这个场景fastjson1的parse算法不擅长的。这个场景fastjson2表现仍然非常好,性能是jackson/gson两倍以上。 这个场景在ecs.c7.xlarge-jdk1.8.0_361环境下,fastjson1的性能是fastjson2的27.83%,jackson的性能是fastjson2的50.51%,gson是fastjson2的42.48%%.

这个场景在fastjson中的代码如下:

// 这里输入的是格式化过后的json字符串
String str = "{\n" +
        "\t\"id\":123\n" +
        "}";
Bean bean = JSON.parseJSONObject(str, Bean.class);

性能排序分别如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > jackson > gson  > fastjson1
jdk8  100%        50.51%    42.48%  27.83%
jdk11 100%        51.71%    43.55%  27.66%
jdk17 100%        49.73%    47.17%  32.64%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 950.492 264.502 (27.83%) 480.051 (50.51%) 403.787 (42.48%)
ecs.c7.xlarge jdk-11.0.18 882.294 244.005 (27.66%) 456.278 (51.71%) 384.278 (43.55%)
ecs.c7.xlarge jdk-17.0.6 916.203 299.046 (32.64%) 455.607 (49.73%) 432.176 (47.17%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 860.291 307.326 (35.72%) 458.983 (53.35%) 451.798 (52.52%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 925.208 383.939 (41.5%) 486.794 (52.61%) 432.933 (46.79%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 984.215 319.552 (32.47%) 440.014 (44.71%) 446.381 (45.35%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 986.227 400.241 (40.58%) 430.902 (43.69%) 432.537 (43.86%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 692.936 213.283 (30.78%) 334.575 (48.28%) 320.859 (46.3%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 775.711 240.271 (30.97%) 376.576 (48.55%) 348.568 (44.94%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 800.644 261.491 (32.66%) 358.895 (44.83%) 335.13 (41.86%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 765.851 227.564 (29.71%) 362.652 (47.35%) 365.554 (47.73%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 773.397 293.269 (37.92%) 389.924 (50.42%) 355.595 (45.98%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 839.161 269.392 (32.1%) 350.737 (41.8%) 332.823 (39.66%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 843.844 336.42 (39.87%) 397.203 (47.07%) 389.916 (46.21%)
OrangePi5 jdk1.8.0_361 526.29 157.851 (29.99%) 244.421 (46.44%) 202.658 (38.51%)
OrangePi5 jdk-11.0.18 516.37 162.004 (31.37%) 250.162 (48.45%) 205.997 (39.89%)
OrangePi5 jdk-17.0.6 519.434 186.118 (35.83%) 255.614 (49.21%) 210.992 (40.62%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 533.864 158.643 (29.72%) 249.753 (46.78%) 206.878 (38.75%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 518.258 162.592 (31.37%) 249.892 (48.22%) 212.44 (40.99%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 516.241 184.0 (35.64%) 261.052 (50.57%) 212.039 (41.07%)
OrangePi5 graalvm-ce-java11-22.3.1 494.209 156.47 (31.66%) 235.566 (47.67%) 201.378 (40.75%)
OrangePi5 graalvm-ce-java17-22.3.1 525.441 192.104 (36.56%) 256.53 (48.82%) 210.713 (40.1%)
OrangePi5 graalvm-ee-java11-22.3.1 590.046 178.705 (30.29%) 260.788 (44.2%) 207.462 (35.16%)
OrangePi5 graalvm-ee-java17-22.3.1 593.73 222.694 (37.51%) 265.651 (44.74%) 222.444 (37.47%)
AppleM1Pro zulu-8.jdk 1504.423 437.956 (29.11%) 686.434 (45.63%) 619.225 (41.16%)
AppleM1Pro zulu-11.jdk 1603.484 330.791 (20.63%) 685.482 (42.75%) 652.634 (40.7%)
AppleM1Pro zulu-17.jdk 1626.052 406.564 (25%) 612.241 (37.65%) 703.953 (43.29%)
AppleM1Pro graalvm-ce-java11-22.3.1 1069.261 329.727 (30.84%) 500.257 (46.79%) 654.819 (61.24%)
AppleM1Pro graalvm-ce-java17-22.3.1 1220.871 368.599 (30.19%) 554.677 (45.43%) 646.939 (52.99%)
AppleM1Pro graalvm-ee-java11-22.3.1 1130.159 406.58 (35.98%) 642.377 (56.84%) 641.67 (56.78%)
AppleM1Pro graalvm-ee-java17-22.3.1 1429.477 479.625 (33.55%) 675.86 (47.28%) 773.832 (54.13%)

2.3 EishayParseTreeString

这个场景是将JSON格式字符串反序列化为JSONObject,这也是一个最常见的场景之一,这个场景在fastjson中的代码如下:

String str = "...";
JSONObject jsonObject = JSON.parseJSONObject(str);

fastjson2在这个场景也表现了远超fastjson1/jackson/gson的性能。 在不同的环境中,fastjson1和jackson都只能相当于fastjson2性能的40%~60%,gson则更差一些。

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > fastjson1 > jackson  > gson
jdk8  100%        53.74%      58.62%     35.10%
jdk11 100%        46.49%      56.86%     37.41%
jdk17 100%        53.27%      50.06%     31.39%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 937.001 503.555 (53.74%) 549.272 (58.62%) 328.918 (35.1%)
ecs.c7.xlarge jdk-11.0.18 828.292 385.063 (46.49%) 470.965 (56.86%) 310.019 (37.43%)
ecs.c7.xlarge jdk-17.0.6 1051.942 560.349 (53.27%) 526.592 (50.06%) 330.198 (31.39%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 907.201 500.731 (55.2%) 527.568 (58.15%) 432.917 (47.72%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1008.033 663.72 (65.84%) 514.445 (51.03%) 443.003 (43.95%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1010.722 599.252 (59.29%) 555.966 (55.01%) 402.95 (39.87%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1093.144 689.876 (63.11%) 550.792 (50.39%) 411.828 (37.67%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 541.912 311.489 (57.48%) 285.566 (52.7%) 260.213 (48.02%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 784.292 358.608 (45.72%) 356.512 (45.46%) 253.098 (32.27%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 788.952 410.028 (51.97%) 388.191 (49.2%) 307.036 (38.92%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 753.186 408.072 (54.18%) 434.595 (57.7%) 389.662 (51.74%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 779.154 522.35 (67.04%) 464.977 (59.68%) 392.152 (50.33%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 850.952 487.95 (57.34%) 395.934 (46.53%) 336.719 (39.57%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 886.776 583.074 (65.75%) 477.923 (53.89%) 375.97 (42.4%)
OrangePi5 jdk1.8.0_361 429.501 220.208 (51.27%) 238.991 (55.64%) 174.63 (40.66%)
OrangePi5 jdk-11.0.18 477.027 239.215 (50.15%) 250.949 (52.61%) 184.971 (38.78%)
OrangePi5 jdk-17.0.6 486.906 286.966 (58.94%) 263.94 (54.21%) 180.124 (36.99%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 444.139 216.911 (48.84%) 242.465 (54.59%) 181.385 (40.84%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 482.102 245.358 (50.89%) 251.589 (52.19%) 188.718 (39.14%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 480.617 276.605 (57.55%) 265.28 (55.2%) 178.217 (37.08%)
OrangePi5 graalvm-ce-java11-22.3.1 464.549 260.688 (56.12%) 287.791 (61.95%) 204.224 (43.96%)
OrangePi5 graalvm-ce-java17-22.3.1 463.534 335.267 (72.33%) 298.068 (64.3%) 202.707 (43.73%)
OrangePi5 graalvm-ee-java11-22.3.1 530.376 326.643 (61.59%) 286.0 (53.92%) 201.99 (38.08%)
OrangePi5 graalvm-ee-java17-22.3.1 544.288 383.122 (70.39%) 300.762 (55.26%) 201.14 (36.95%)
AppleM1Pro zulu-8.jdk 1383.601 682.974 (49.36%) 745.159 (53.86%) 543.104 (39.25%)
AppleM1Pro zulu-11.jdk 1249.748 518.881 (41.52%) 711.815 (56.96%) 571.768 (45.75%)
AppleM1Pro zulu-17.jdk 1500.9 773.547 (51.54%) 778.36 (51.86%) 551.099 (36.72%)
AppleM1Pro graalvm-ce-java11-22.3.1 1329.152 704.437 (53%) 769.372 (57.88%) 627.962 (47.25%)
AppleM1Pro graalvm-ce-java17-22.3.1 1306.475 845.879 (64.75%) 817.492 (62.57%) 604.223 (46.25%)
AppleM1Pro graalvm-ee-java11-22.3.1 1605.859 1033.659 (64.37%) 876.563 (54.59%) 625.542 (38.95%)
AppleM1Pro graalvm-ee-java17-22.3.1 1615.447 1152.589 (71.35%) 893.775 (55.33%) 621.6 (38.48%)

2.4 EishayParseUTF8Bytes

这个是将UTF8格式的byte数组反序列化为Java对象,这个场景在缓存和RPC场景中常用。

这个场景在fastjson中的代码如下:

byte[] utf8Bytes = ...;
Bean bean = JSON.parseJSONObject(utf8Bytes, Bean.class);

这个场景fastjson2同样表现出了卓越的性能;在JDK8下,fastjson1和jackson的性能分别之后fastjson2的70.64%和55.14%; gson不直接支持输入utf8Bytes,需要先构造字符串,性能只有fastjson2的28.89%。

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > fastjson1 > jackson  > gson
jdk8  100%        70.64%      55.14%     28.89%
jdk11 100%        61.82%      43.93%     25.77%
jdk17 100%        72.54%      42.07%     24.12%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 dsljson fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 1096.18 906.579 (82.7%) 774.381 (70.64%) 604.382 (55.14%) 316.737 (28.89%)
ecs.c7.xlarge jdk-11.0.18 1210.481 869.425 (71.82%) 748.264 (61.82%) 531.783 (43.93%) 311.924 (25.77%)
ecs.c7.xlarge jdk-17.0.6 1321.512 828.617 (62.7%) 958.636 (72.54%) 555.918 (42.07%) 318.736 (24.12%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1108.37 908.666 (81.98%) 789.996 (71.28%) 561.613 (50.67%) 406.713 (36.69%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1212.54 587.961 (48.49%) 942.844 (77.76%) 595.836 (49.14%) 410.623 (33.86%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1390.966 954.264 (68.6%) 849.153 (61.05%) 527.476 (37.92%) 405.754 (29.17%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1360.851 886.295 (65.13%) 1112.657 (81.76%) 560.24 (41.17%) 423.122 (31.09%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 793.331 582.611 (73.44%) 665.914 (83.94%) 405.807 (51.15%) 234.937 (29.61%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1086.999 658.185 (60.55%) 598.385 (55.05%) 456.233 (41.97%) 296.384 (27.27%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1110.109 575.938 (51.88%) 670.278 (60.38%) 461.75 (41.6%) 298.194 (26.86%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 857.433 655.337 (76.43%) 548.097 (63.92%) 417.743 (48.72%) 304.206 (35.48%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 893.457 315.774 (35.34%) 744.984 (83.38%) 465.428 (52.09%) 350.877 (39.27%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1037.866 716.506 (69.04%) 474.25 (45.69%) 415.033 (39.99%) 346.433 (33.38%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1025.837 585.251 (57.05%) 864.922 (84.31%) 443.048 (43.19%) 361.208 (35.21%)
OrangePi5 jdk1.8.0_361 558.42 431.222 (77.22%) 403.504 (72.26%) 319.153 (57.15%) 150.852 (27.01%)
OrangePi5 jdk-11.0.18 688.989 442.887 (64.28%) 454.815 (66.01%) 305.389 (44.32%) 177.047 (25.7%)
OrangePi5 jdk-17.0.6 705.224 432.798 (61.37%) 590.042 (83.67%) 315.579 (44.75%) 168.232 (23.86%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 545.892 467.42 (85.62%) 410.986 (75.29%) 327.339 (59.96%) 156.605 (28.69%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 683.102 432.304 (63.29%) 458.947 (67.19%) 308.228 (45.12%) 174.696 (25.57%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 694.599 433.148 (62.36%) 583.093 (83.95%) 308.434 (44.4%) 168.247 (24.22%)
OrangePi5 graalvm-ce-java11-22.3.1 502.684 424.983 (84.54%) 388.579 (77.3%) 283.009 (56.3%) 176.509 (35.11%)
OrangePi5 graalvm-ce-java17-22.3.1 539.197 304.26 (56.43%) 477.918 (88.64%) 296.896 (55.06%) 177.988 (33.01%)
OrangePi5 graalvm-ee-java11-22.3.1 704.301 464.165 (65.9%) 401.703 (57.04%) 282.421 (40.1%) 186.554 (26.49%)
OrangePi5 graalvm-ee-java17-22.3.1 695.452 450.626 (64.8%) 518.567 (74.57%) 298.25 (42.89%) 187.919 (27.02%)
AppleM1Pro zulu-8.jdk 1359.371 1033.84 (76.05%) 1467.446 (107.95%) 1001.071 (73.64%) 592.32 (43.57%)
AppleM1Pro zulu-11.jdk 1683.926 662.507 (39.34%) 1288.777 (76.53%) 860.343 (51.09%) 563.696 (33.48%)
AppleM1Pro zulu-17.jdk 1725.803 684.458 (39.66%) 1690.625 (97.96%) 772.636 (44.77%) 560.202 (32.46%)
AppleM1Pro graalvm-ce-java11-22.3.1 900.795 678.463 (75.32%) 840.785 (93.34%) 712.219 (79.07%) 531.893 (59.05%)
AppleM1Pro graalvm-ce-java17-22.3.1 822.471 470.923 (57.26%) 1064.558 (129.43%) 739.915 (89.96%) 543.342 (66.06%)
AppleM1Pro graalvm-ee-java11-22.3.1 1216.992 767.458 (63.06%) 1145.801 (94.15%) 812.695 (66.78%) 601.589 (49.43%)
AppleM1Pro graalvm-ee-java17-22.3.1 1275.869 691.136 (54.17%) 1446.879 (113.4%) 781.229 (61.23%) 587.987 (46.09%)

2.5 EishayWriteString

这个是Java对象序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:

Bean bean = ...;
String str = JSON.toJSONString(bean);

在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的20~30%。

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > jackson >   fastjson1  > gson
jdk8  100%        69.80%      43.32%       30.74%
jdk11 100%        62.51%      39.23%       24.60%
jdk17 100%        62.10%      37.16%       14.65%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 1425.406 617.465 (43.32%) 994.869 (69.8%) 438.237 (30.74%)
ecs.c7.xlarge jdk-11.0.18 1493.577 585.857 (39.23%) 933.701 (62.51%) 367.352 (24.6%)
ecs.c7.xlarge jdk-17.0.6 1665.65 618.883 (37.16%) 1034.405 (62.1%) 243.952 (14.65%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1606.809 747.114 (46.5%) 939.963 (58.5%) 382.962 (23.83%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1808.327 822.504 (45.48%) 993.322 (54.93%) 243.883 (13.49%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1869.074 765.314 (40.95%) 964.817 (51.62%) 348.469 (18.64%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1862.843 778.555 (41.79%) 1014.458 (54.46%) 245.77 (13.19%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 1228.957 527.376 (42.91%) 638.52 (51.96%) 367.988 (29.94%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1313.549 498.395 (37.94%) 508.149 (38.69%) 319.698 (24.34%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1299.443 500.116 (38.49%) 735.252 (56.58%) 225.756 (17.37%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1359.618 595.57 (43.8%) 738.149 (54.29%) 325.288 (23.92%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1452.891 682.347 (46.96%) 733.532 (50.49%) 202.412 (13.93%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1558.98 563.327 (36.13%) 780.298 (50.05%) 291.926 (18.73%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1589.79 637.783 (40.12%) 839.328 (52.79%) 194.536 (12.24%)
OrangePi5 jdk1.8.0_361 697.023 283.573 (40.68%) 388.961 (55.8%) 200.77 (28.8%)
OrangePi5 jdk-11.0.18 854.896 332.814 (38.93%) 423.161 (49.5%) 208.743 (24.42%)
OrangePi5 jdk-17.0.6 845.826 340.099 (40.21%) 460.896 (54.49%) 169.121 (19.99%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 700.6 309.593 (44.19%) 397.103 (56.68%) 209.554 (29.91%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 834.15 297.573 (35.67%) 411.863 (49.38%) 209.395 (25.1%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 836.831 325.713 (38.92%) 453.249 (54.16%) 165.031 (19.72%)
OrangePi5 graalvm-ce-java11-22.3.1 902.48 345.487 (38.28%) 422.514 (46.82%) 190.203 (21.08%)
OrangePi5 graalvm-ce-java17-22.3.1 976.7 388.328 (39.76%) 450.476 (46.12%) 152.852 (15.65%)
OrangePi5 graalvm-ee-java11-22.3.1 1036.237 409.167 (39.49%) 496.696 (47.93%) 213.704 (20.62%)
OrangePi5 graalvm-ee-java17-22.3.1 1022.405 416.465 (40.73%) 512.964 (50.17%) 164.976 (16.14%)
AppleM1Pro zulu-8.jdk 2920.647 1231.183 (42.15%) 1725.935 (59.09%) 755.44 (25.87%)
AppleM1Pro zulu-11.jdk 2905.056 873.541 (30.07%) 1667.165 (57.39%) 660.575 (22.74%)
AppleM1Pro zulu-17.jdk 2903.157 1165.985 (40.16%) 1701.044 (58.59%) 563.059 (19.39%)
AppleM1Pro graalvm-ce-java11-22.3.1 2850.243 1027.243 (36.04%) 1542.75 (54.13%) 618.574 (21.7%)
AppleM1Pro graalvm-ce-java17-22.3.1 2940.466 1107.522 (37.66%) 1582.944 (53.83%) 425.238 (14.46%)
AppleM1Pro graalvm-ee-java11-22.3.1 3378.575 1442.432 (42.69%) 1818.591 (53.83%) 720.659 (21.33%)
AppleM1Pro graalvm-ee-java17-22.3.1 3377.665 1402.821 (41.53%) 1842.14 (54.54%) 436.091 (12.91%)

2.6 EishayWriteUTF8Bytes

这个是Java对象序列化成UTF格式的byte数组, 这个是最常用的场景之一,在缓存和RPC场景常用。gson不直接支持,需要先序列化为String再转换为UTF8格式的byte数组。

这个场景在fastjson中的代码如下:

Bean bean = ...;
byte[] utf8Bytes = JSON.toJSONBytes(bean);

在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的1/5不到,在JDK 17下差距更大。

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > jackson >   fastjson1  > gson
jdk8  100%        61.12%      38.71%       25.33%
jdk11 100%        53.84%      33.78%       22.35%
jdk17 100%        51.49%      39.50%       12.57%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是fastjson1/fastjson2的百分数表示。

aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 1514.597 586.257 (38.71%) 925.776 (61.12%) 383.59 (25.33%)
ecs.c7.xlarge jdk-11.0.18 1611.243 544.291 (33.78%) 867.523 (53.84%) 360.092 (22.35%)
ecs.c7.xlarge jdk-17.0.6 1933.337 570.384 (29.5%) 995.436 (51.49%) 242.848 (12.56%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1746.746 656.17 (37.57%) 890.242 (50.97%) 375.456 (21.49%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 2013.978 704.27 (34.97%) 1027.116 (51%) 235.18 (11.68%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1905.032 662.968 (34.8%) 1019.631 (53.52%) 346.769 (18.2%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1968.037 757.226 (38.48%) 1077.563 (54.75%) 241.234 (12.26%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 1327.63 474.679 (35.75%) 684.044 (51.52%) 316.015 (23.8%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1443.41 479.086 (33.19%) 659.749 (45.71%) 323.705 (22.43%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1422.573 484.949 (34.09%) 676.498 (47.55%) 216.899 (15.25%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1443.326 481.925 (33.39%) 714.137 (49.48%) 303.389 (21.02%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1459.487 438.033 (30.01%) 621.988 (42.62%) 197.419 (13.53%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1176.633 573.537 (48.74%) 608.454 (51.71%) 306.786 (26.07%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1630.648 681.073 (41.77%) 909.14 (55.75%) 226.497 (13.89%)
OrangePi5 jdk1.8.0_361 829.612 283.21 (34.14%) 394.135 (47.51%) 166.997 (20.13%)
OrangePi5 jdk-11.0.18 913.22 267.425 (29.28%) 389.362 (42.64%) 196.843 (21.55%)
OrangePi5 jdk-17.0.6 937.373 302.058 (32.22%) 427.692 (45.63%) 159.198 (16.98%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 826.952 281.028 (33.98%) 408.753 (49.43%) 166.595 (20.15%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 899.63 274.218 (30.48%) 380.068 (42.25%) 192.954 (21.45%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 909.607 294.593 (32.39%) 410.103 (45.09%) 162.192 (17.83%)
OrangePi5 graalvm-ce-java11-22.3.1 957.745 280.481 (29.29%) 394.493 (41.19%) 169.404 (17.69%)
OrangePi5 graalvm-ce-java17-22.3.1 916.122 285.561 (31.17%) 442.525 (48.3%) 137.72 (15.03%)
OrangePi5 graalvm-ee-java11-22.3.1 1075.593 313.015 (29.1%) 502.284 (46.7%) 204.853 (19.05%)
OrangePi5 graalvm-ee-java17-22.3.1 1096.023 415.298 (37.89%) 551.924 (50.36%) 156.955 (14.32%)
AppleM1Pro zulu-8.jdk 2867.095 1073.02 (37.43%) 1580.438 (55.12%) 664.498 (23.18%)
AppleM1Pro zulu-11.jdk 3137.584 1050.521 (33.48%) 1400.792 (44.65%) 656.054 (20.91%)
AppleM1Pro zulu-17.jdk 3119.823 1053.009 (33.75%) 1532.711 (49.13%) 558.694 (17.91%)
AppleM1Pro graalvm-ce-java11-22.3.1 3013.692 794.869 (26.38%) 1408.752 (46.75%) 519.76 (17.25%)
AppleM1Pro graalvm-ce-java17-22.3.1 3099.143 832.224 (26.85%) 1633.592 (52.71%) 383.137 (12.36%)
AppleM1Pro graalvm-ee-java11-22.3.1 3548.491 1003.143 (28.27%) 1861.546 (52.46%) 651.919 (18.37%)
AppleM1Pro graalvm-ee-java17-22.3.1 3547.541 1249.904 (35.23%) 1955.23 (55.12%) 424.858 (11.98%)

2.7 EishayWriteStringTree

这个场景是JSONObject序列化成字符串, 这个是序列化最常用的场景之一。这个场景在fastjson中的代码如下:

JSONObject jsonObject = ...;
String str = jsonObject.toJSONString();

在这个最常用的序列化场景,fastjson2表现出远超fastjson1/jackson/gson的性能;这个场景gson表现很差,只有fastjson2的1/3

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2 > jackson >   fastjson1  > gson
jdk8  100%        78.39%      69.10%       39.00%
jdk11 100%        76.60%      62.46%       30.83%
jdk17 100%        72.75%      67.30%       20.93%
aliyun ecs spec jdk version fastjson2 fastjson1 jackson gson
ecs.c7.xlarge jdk1.8.0_361 1210.47 836.378 (69.1%) 948.87 (78.39%) 472.093 (39%)
ecs.c7.xlarge jdk-11.0.18 1245.471 777.902 (62.46%) 953.973 (76.6%) 384.021 (30.83%)
ecs.c7.xlarge jdk-17.0.6 1183.837 796.732 (67.3%) 861.244 (72.75%) 247.782 (20.93%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1453.595 769.232 (52.92%) 1012.782 (69.67%) 428.776 (29.5%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1426.993 850.943 (59.63%) 993.654 (69.63%) 247.528 (17.35%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1410.312 821.212 (58.23%) 929.05 (65.88%) 380.692 (26.99%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1468.635 923.037 (62.85%) 955.151 (65.04%) 248.857 (16.94%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 923.546 578.77 (62.67%) 686.736 (74.36%) 406.305 (43.99%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1077.641 565.756 (52.5%) 719.522 (66.77%) 353.722 (32.82%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1063.744 629.448 (59.17%) 668.78 (62.87%) 204.293 (19.21%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1288.057 399.494 (31.02%) 765.545 (59.43%) 351.411 (27.28%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1322.254 590.783 (44.68%) 780.373 (59.02%) 214.569 (16.23%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1230.258 596.169 (48.46%) 831.389 (67.58%) 271.493 (22.07%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1234.846 557.317 (45.13%) 797.71 (64.6%) 237.216 (19.21%)
OrangePi5 jdk1.8.0_361 489.998 327.315 (66.8%) 398.634 (81.35%) 228.081 (46.55%)
OrangePi5 jdk-11.0.18 605.653 366.04 (60.44%) 449.373 (74.2%) 219.655 (36.27%)
OrangePi5 jdk-17.0.6 603.249 371.986 (61.66%) 411.374 (68.19%) 169.894 (28.16%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 486.045 334.141 (68.75%) 392.898 (80.84%) 222.099 (45.7%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 606.39 357.93 (59.03%) 445.661 (73.49%) 219.91 (36.27%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 596.849 378.95 (63.49%) 409.102 (68.54%) 165.595 (27.74%)
OrangePi5 graalvm-ce-java11-22.3.1 692.056 249.597 (36.07%) 462.169 (66.78%) 190.225 (27.49%)
OrangePi5 graalvm-ce-java17-22.3.1 701.439 400.559 (57.11%) 471.477 (67.22%) 161.006 (22.95%)
OrangePi5 graalvm-ee-java11-22.3.1 719.49 398.441 (55.38%) 511.884 (71.15%) 252.031 (35.03%)
OrangePi5 graalvm-ee-java17-22.3.1 723.293 406.072 (56.14%) 516.136 (71.36%) 181.882 (25.15%)
AppleM1Pro zulu-8.jdk 1880.707 1284.724 (68.31%) 1582.641 (84.15%) 836.171 (44.46%)
AppleM1Pro zulu-11.jdk 1948.896 1205.387 (61.85%) 1538.286 (78.93%) 698.374 (35.83%)
AppleM1Pro zulu-17.jdk 1922.846 1270.139 (66.06%) 1428.381 (74.28%) 567.825 (29.53%)
AppleM1Pro graalvm-ce-java11-22.3.1 2128.637 415.942 (19.54%) 1421.899 (66.8%) 600.107 (28.19%)
AppleM1Pro graalvm-ce-java17-22.3.1 2174.637 515.559 (23.71%) 1436.395 (66.05%) 434.806 (19.99%)
AppleM1Pro graalvm-ee-java11-22.3.1 2308.892 1011.721 (43.82%) 1553.488 (67.28%) 804.692 (34.85%)
AppleM1Pro graalvm-ee-java17-22.3.1 2296.148 1100.832 (47.94%) 1575.639 (68.62%) 442.203 (19.26%)

2.8 EishayWriteBinaryAutoType

这个场景是将JavaBean序列化成二进制格式并且带类型信息, 这个是代替Java/Hessian序列化的场景,代码如下:

JSONB.toBytes(
        mc,
        JSONWriter.Feature.WriteClassName,
        JSONWriter.Feature.IgnoreNoneSerializable,
        JSONWriter.Feature.FieldBased,
        JSONWriter.Feature.ReferenceDetection,
        JSONWriter.Feature.WriteNulls,
        JSONWriter.Feature.NotWriteDefaultValue,
        JSONWriter.Feature.NotWriteHashMapArrayListClassName,
        JSONWriter.Feature.WriteNameAsSymbol
)

这个场景下,fastjson_jsonb的性能是hessian的4~5倍

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2_jsonb > fastjson2UTF8Bytes >   hessian  > javaSerialize
jdk8  100%              114.53%                 26.16%     18.38%
jdk11 100%              107.65%                 23.20%     15.11%
jdk17 100%              107.24%                 18.81%     13.12%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是hessian/fastjson2_jsonb的百分数表示。

aliyun ecs spec jdk version fastjson2JSONB fastjson2UTF8Bytes hessian javaSerialize
ecs.c7.xlarge jdk1.8.0_361 1291.535 1479.158 (114.53%) 337.889 (26.16%) 237.405 (18.38%)
ecs.c7.xlarge jdk-11.0.18 1428.065 1537.336 (107.65%) 331.241 (23.2%) 215.735 (15.11%)
ecs.c7.xlarge jdk-17.0.6 1693.082 1815.614 (107.24%) 318.398 (18.81%) 222.138 (13.12%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1396.239 1751.419 (125.44%) 394.779 (28.27%) 220.306 (15.78%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 1595.988 1937.926 (121.42%) 403.981 (25.31%) 230.418 (14.44%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 1835.485 1869.377 (101.85%) 477.947 (26.04%) 241.992 (13.18%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 1888.25 1935.391 (102.5%) 484.813 (25.68%) 239.056 (12.66%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 1104.415 1271.763 (115.15%) 342.973 (31.05%) 206.399 (18.69%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1333.008 1340.094 (100.53%) 341.067 (25.59%) 221.196 (16.59%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1345.119 1338.188 (99.48%) 334.523 (24.87%) 200.052 (14.87%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1438.112 1421.519 (98.85%) 327.771 (22.79%) 196.688 (13.68%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1462.628 1238.75 (84.69%) 343.872 (23.51%) 188.163 (12.86%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 1595.686 1586.706 (99.44%) 376.571 (23.6%) 225.757 (14.15%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1620.882 1407.184 (86.82%) 388.458 (23.97%) 220.251 (13.59%)
OrangePi5 jdk1.8.0_361 670.145 787.483 (117.51%) 182.971 (27.3%) 121.381 (18.11%)
OrangePi5 jdk-11.0.18 765.039 854.113 (111.64%) 187.995 (24.57%) 132.902 (17.37%)
OrangePi5 jdk-17.0.6 784.785 857.41 (109.25%) 200.916 (25.6%) 130.687 (16.65%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 695.575 783.995 (112.71%) 186.741 (26.85%) 121.849 (17.52%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 786.712 908.625 (115.5%) 198.441 (25.22%) 133.281 (16.94%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 781.496 841.561 (107.69%) 213.961 (27.38%) 132.455 (16.95%)
OrangePi5 graalvm-ce-java11-22.3.1 785.729 911.11 (115.96%) 115.633 (14.72%) 113.07 (14.39%)
OrangePi5 graalvm-ce-java17-22.3.1 804.7 927.335 (115.24%) 168.707 (20.97%) 107.005 (13.3%)
OrangePi5 graalvm-ee-java11-22.3.1 873.84 1060.122 (121.32%) 206.628 (23.65%) 131.239 (15.02%)
OrangePi5 graalvm-ee-java17-22.3.1 899.851 1069.621 (118.87%) 222.86 (24.77%) 127.619 (14.18%)
AppleM1Pro zulu-8.jdk 2486.244 2808.383 (112.96%) 616.722 (24.81%) 437.507 (17.6%)
AppleM1Pro zulu-11.jdk 2911.123 3046.631 (104.65%) 678.153 (23.3%) 434.057 (14.91%)
AppleM1Pro zulu-17.jdk 2944.208 3062.764 (104.03%) 690.683 (23.46%) 445.123 (15.12%)
AppleM1Pro graalvm-ce-java11-22.3.1 2408.305 2933.396 (121.8%) 424.785 (17.64%) 379.246 (15.75%)
AppleM1Pro graalvm-ce-java17-22.3.1 3046.257 2990.2 (98.16%) 691.908 (22.71%) 384.065 (12.61%)
AppleM1Pro graalvm-ee-java11-22.3.1 3553.814 3491.858 (98.26%) 829.438 (23.34%) 484.086 (13.62%)
AppleM1Pro graalvm-ee-java17-22.3.1 3576.012 3498.38 (97.83%) 836.026 (23.38%) 477.541 (13.35%)

2.9 EishayParseBinaryAutoType

这个场景是JavaBean二进制带类型信息反序列化的场景, 这个是代替Java/Hessian反序列化的场景,代码如下:

JSONB.parseObject(
        fastjson2JSONBBytes,
        Object.class,
        JSONReader.Feature.SupportAutoType,
        JSONReader.Feature.IgnoreNoneSerializable,
        JSONReader.Feature.UseDefaultConstructorAsPossible,
        JSONReader.Feature.UseNativeObject,
        JSONReader.Feature.FieldBased)

这个场景下,fastjson2二进制格式性能是hessian的58倍,是Java序列化的3040倍

性能排序如下:

// ecs.c7.xlarge-oracle-jdk1.8.0_361_x64

      fastjson2_jsonb > fastjson2JSONB_autoTypeFilter >   hessian  > javaSerialize
jdk8  100%              95.97%                            20.29%     3.29%
jdk11 100%              85.03%                            13.21%     2.61%
jdk17 100%              81.94%                            11.95%     2.47%

下面是不同CPU不同JDK下的性能比较表格,第1列是阿里云机器规格,第2列是JDK的版本信息,第3列到第6列是不同库的JMH的Throughput数据,越大越好。 第4列到第6列中的百分比是Throughput相比fastjson2的比,比如第三列的百分比是hessian/fastjson2_jsonb的百分数表示。

aliyun ecs spec jdk version fastjson2JSONB fastjson2JSONB_autoTypeFilter hessian javaSerialize
ecs.c7.xlarge jdk1.8.0_361 1422.034 1364.731 (95.97%) 288.511 (20.29%) 46.836 (3.29%)
ecs.c7.xlarge jdk-11.0.18 1915.518 1628.745 (85.03%) 252.958 (13.21%) 49.918 (2.61%)
ecs.c7.xlarge jdk-17.0.6 2182.57 1788.478 (81.94%) 260.831 (11.95%) 53.998 (2.47%)
ecs.c7.xlarge graalvm-ce-java11-22.3.1 1946.455 1819.101 (93.46%) 244.481 (12.56%) 48.71 (2.5%)
ecs.c7.xlarge graalvm-ce-java17-22.3.1 2163.645 1999.622 (92.42%) 243.163 (11.24%) 53.245 (2.46%)
ecs.c7.xlarge graalvm-ee-java11-22.3.1 2497.174 2366.851 (94.78%) 340.038 (13.62%) 52.586 (2.11%)
ecs.c7.xlarge graalvm-ee-java17-22.3.1 2173.272 2126.769 (97.86%) 406.181 (18.69%) 56.769 (2.61%)
ecs.g8m.xlarge jdk1.8.0_341_aarch64 1197.997 1079.51 (90.11%) 221.253 (18.47%) 42.356 (3.54%)
ecs.g8m.xlarge jdk-11.0.16_aarch64 1603.91 1565.631 (97.61%) 213.897 (13.34%) 41.488 (2.59%)
ecs.g8m.xlarge jdk-17.0.4_aarch64 1668.87 1596.504 (95.66%) 220.028 (13.18%) 41.345 (2.48%)
ecs.g8m.xlarge graalvm-ce-java11-22.3.1 1755.044 1595.831 (90.93%) 178.006 (10.14%) 40.116 (2.29%)
ecs.g8m.xlarge graalvm-ce-java17-22.3.1 1830.315 1654.022 (90.37%) 182.033 (9.95%) 41.061 (2.24%)
ecs.g8m.xlarge graalvm-ee-java11-22.3.1 2019.136 1792.204 (88.76%) 308.212 (15.26%) 44.665 (2.21%)
ecs.g8m.xlarge graalvm-ee-java17-22.3.1 1851.247 1782.03 (96.26%) 344.444 (18.61%) 41.849 (2.26%)
OrangePi5 jdk1.8.0_361 635.463 637.63 (100.34%) 132.544 (20.86%) 26.736 (4.21%)
OrangePi5 jdk-11.0.18 808.881 792.967 (98.03%) 135.712 (16.78%) 26.256 (3.25%)
OrangePi5 jdk-17.0.6 829.524 837.154 (100.92%) 154.807 (18.66%) 29.375 (3.54%)
OrangePi5 zulu8.68.0.21-ca-jdk8.0.362-linux_aarch64 638.954 635.161 (99.41%) 151.588 (23.72%) 26.268 (4.11%)
OrangePi5 zulu11.62.17-ca-jdk11.0.18-linux_aarch64 812.588 796.373 (98%) 138.747 (17.07%) 26.637 (3.28%)
OrangePi5 zulu17.40.19-ca-jdk17.0.6-linux_aarch64 832.33 842.515 (101.22%) 154.06 (18.51%) 29.019 (3.49%)
OrangePi5 graalvm-ce-java11-22.3.1 936.106 725.177 (77.47%) 109.969 (11.75%) 25.765 (2.75%)
OrangePi5 graalvm-ce-java17-22.3.1 1003.736 903.315 (90%) 120.538 (12.01%) 27.393 (2.73%)
OrangePi5 graalvm-ee-java11-22.3.1 1078.773 950.072 (88.07%) 170.881 (15.84%) 28.532 (2.64%)
OrangePi5 graalvm-ee-java17-22.3.1 1246.679 1028.082 (82.47%) 207.444 (16.64%) 29.796 (2.39%)
AppleM1Pro zulu-8.jdk 2543.596 2400.162 (94.36%) 382.938 (15.05%) 58.475 (2.3%)
AppleM1Pro zulu-11.jdk 3104.45 2856.737 (92.02%) 378.538 (12.19%) 61.46 (1.98%)
AppleM1Pro zulu-17.jdk 3204.135 2958.608 (92.34%) 328.21 (10.24%) 67.91 (2.12%)
AppleM1Pro graalvm-ce-java11-22.3.1 3282.771 2295.789 (69.93%) 277.959 (8.47%) 57.119 (1.74%)
AppleM1Pro graalvm-ce-java17-22.3.1 3157.392 2938.32 (93.06%) 277.677 (8.79%) 63.104 (2%)
AppleM1Pro graalvm-ee-java11-22.3.1 3316.959 3204.476 (96.61%) 515.237 (15.53%) 62.465 (1.88%)
AppleM1Pro graalvm-ee-java17-22.3.1 3330.798 3331.443 (100.02%) 671.593 (20.16%) 69.338 (2.08%)
Clone this wiki locally