bytedance / sonic-cpp

A fast JSON serializing & deserializing library, accelerated by SIMD.
Apache License 2.0
835 stars 101 forks source link

feat: support lazynode #55

Closed liuq19 closed 1 year ago

liuq19 commented 1 year ago

背景

在部分业务场景下,只需要 json 中的特定字段。而 parseondemand api 虽然能按需解析,但是不够灵活。 因此,设计一种新的基于 simdskip 的 lazynode。 lazynode 的 api 力求完全与现有的 dynamic node 兼容。

设计

  1. 是否需要拷贝 JSON 串? 目前,lazynode 的 dom 树默认不拷贝 json 串。dynamicnode 的 dom 树会拷贝整个 json 串 做 string buffer。

  2. lazynode 数据结构? lazynode 带有一个 alloc_ 成员,用以无感知地进行内存分配等操作。因此,lazynode 比 dynamicnode 多 8 bytes 内存占用。

  3. lazynode 的 API 和 dynamicnode 的区别? API 名字保持一致,但内在实现不同。 lazynode 的 dom 树,parse 时只解析第一层。 lazynode 的 Get 和 Check API,都会进行 node 的展开。

性能测试

codecov-commenter commented 1 year ago

Codecov Report

Merging #55 (949746b) into master (80cdba0) will decrease coverage by 0.11%. The diff coverage is 91.13%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master      #55      +/-   ##
==========================================
- Coverage   95.04%   94.94%   -0.11%     
==========================================
  Files          22       23       +1     
  Lines        2785     3362     +577     
==========================================
+ Hits         2647     3192     +545     
- Misses        138      170      +32     
Impacted Files Coverage Δ
include/sonic/dom/dynamicnode.h 93.40% <15.38%> (-2.69%) :arrow_down:
include/sonic/dom/handler.h 92.17% <42.85%> (-6.88%) :arrow_down:
include/sonic/dom/parser.h 96.15% <88.34%> (+1.91%) :arrow_up:
include/sonic/internal/skip.h 89.84% <93.33%> (+5.73%) :arrow_up:
include/sonic/dom/genericnode.h 98.26% <93.65%> (-1.37%) :arrow_down:
include/sonic/dom/lazynode.h 94.44% <94.44%> (ø)
include/sonic/dom/generic_document.h 95.91% <100.00%> (+0.31%) :arrow_up:
include/sonic/dom/serialize.h 92.72% <100.00%> (-0.67%) :arrow_down:
include/sonic/experiment/lazy_update.h 88.46% <100.00%> (ø)
include/sonic/allocator.h 87.96% <0.00%> (-2.48%) :arrow_down:
... and 4 more

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

liuq19 commented 1 year ago

验证性能收益不及预期,此 pr 暂时关闭。待需要时才开发 lazynode feature。