Repository navigation
perf: cache ASCII field names up to 32 bytes - #7971
hutiefang76 wants to merge 3 commits into
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
The current run at 52c023b finished with 14 jobs passing and one failure. The Ubuntu/JDK 21 job failed before compilation while downloading Spring BOMs from Maven Central with HTTP 429, including its built-in retry. Could a maintainer rerun that failed job? The six explicit ASCII-reader regressions pass locally on JDK 8 and 17. Both local full-reactor modes report 10,077 tests with zero failures/errors; reflect skips three. This request is for the current Ubuntu/JDK 21 job and supersedes the older-head Ubuntu/JDK 25 request. 中文52c023b 当前 CI 已结束:14 项通过,唯一失败的是 Ubuntu/JDK 21 作业。已读取完整日志,两次尝试均在编译前下载 Spring BOM 时遇到 Maven Central HTTP 429。请维护者协助重跑该失败作业。 六例显式 ASCII reader 回归在本地 JDK 8/17 均通过;两种本地全仓模式均为 10,077 项、无失败或错误,reflect 跳过三项。本次请求对应当前 Ubuntu/JDK 21 作业,取代旧提交 Ubuntu/JDK 25 的请求。 |
What this PR does / why we need it?
Repeated unescaped ASCII field names longer than 16 bytes currently allocate a new
Stringwhen parsing UTF-8 JSON into aJSONObject. This adds a bounded cache for names of 17–32 bytes, covering the repeated long keys in the OTLP metrics example from #7968.Summary of your change
JMH 1.37, JDK 17.0.18, macOS/aarch64, G1, 256 MiB heap, one thread, two forks, 3 × 1 s warmup and 5 × 1 s measurement per fork, GC profiler:
The OTLP payload allocates approximately 448 fewer bytes per parse (4.04%). Throughput error ranges overlap in both comparisons; these measurements do not establish a throughput improvement. The new helper is 285 bytecodes, below the 325-byte C2 frequent-inlining threshold; actual JIT inlining is not claimed.
Local validation:
./mvnw -B -Pgen-code-cov clean test: 10,077 tests, zero failures/errors/skips../mvnw -B -Dfastjson2.creator=reflect clean test: 10,077 tests, zero failures/errors, three skipped.gen-code-cov): 31 of 34 added executable production lines covered (91.18%); both added ASCII-reader lines covered. This is a local report, not an upstream Codecov result../mvnw -B validate: passed across the reactor../mvnw -V --no-transfer-progress -Pgen-javadoc clean packageat 5319278, before the test-only follow-up: passed on JDK 17, including 10,071 tests with zero failures/errors/skips and Javadoc generation. Production and benchmark sources are unchanged by the test follow-up../mvnw -B -pl benchmark -am -DskipTests clean package: passed; this package check skips tests.AI-assisted implementation and review; the reported tests and measurements were executed locally.
Refs #7968.
Please indicate you've done the following:
中文
将 UTF-8 JSON 解析为
JSONObject时,长度超过 16 字节且不含转义的 ASCII 字段名目前会重复分配String。本补丁增加独立的 8,192 槽位缓存,覆盖 17–32 字节字段名,并在命中时比较完整名称,避免哈希碰撞混淆。默认 ASCII reader 和显式 UTF-8 reader 都已覆盖;原有短名称、转义及非 ASCII 处理保持原路径,缓存不保留可变输入缓冲区。新增回归覆盖字段名复用、边界长度、碰撞、偏移和缓冲区复用、并发、两条 reader 路径及 Latin-1 名称。基准包含固定版本的 OpenTelemetry 官方指标样本、Apache-2.0 授权说明,以及仅在 setup 阶段缩短三个长字段名的对照组。
在上述同机 JMH 参数下,OTLP 每次解析分配量约减少 448 字节(4.04%);短键对照的分配量保持相同。两组吞吐量误差范围均重叠,因此不据此宣称吞吐量提升。新辅助方法为 285 字节码,低于 C2 热方法 325 字节的内联阈值,不代表已验证实际内联。
JDK 17 全仓 clean 标准模式(启用 gen-code-cov)10,077 项测试通过,无失败、错误或跳过;全仓 clean reflect 模式同样 10,077 项,无失败或错误,跳过三项。JDK 8/17 两条 reader 的原生探针、全仓静态检查及跳过测试的基准模块 clean package 已通过。两条全仓命令均已成功完成。另已在 5319278(本次仅测试的修订之前)以 JDK 17 完成全仓
-Pgen-javadoc clean package,10,071 项测试及文档生成均通过;运行时及基准源码在这次测试修订中保持相同,JDK 8/17/21 的基准类 doclint 检查也均通过。新增六例显式 ISO-8859-1/ASCII reader 回归在 JDK 8/17 均通过;原始 460d2e4 基线的四例长键复用断言失败,碰撞与缓冲区正确性控制通过。缓冲区用例会在覆盖输入后重新检查第一次解析的结果。本地 JDK 17 JaCoCo 显示新增可执行生产行 31/34(91.18%)已覆盖,其中 ASCII reader 新增两行均覆盖;该结果不代表上游 Codecov。
使用 AI 辅助实现和审查;所报告的数据与测试均在本地实际执行。关联 #7968。