perf(bean): 优化FastBeanCopier默认后端与缓存策略#352
Open
zhou-hao wants to merge 12 commits into
Open
Conversation
# Conflicts: # hsweb-core/pom.xml # hsweb-core/src/main/java/org/hswebframework/web/bean/ClassDescription.java # hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java # pom.xml
# Conflicts: # hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java # hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目的
核心变动
默认 backend 与运行时选择
asm-accessor。FastBeanCopierBackendSelector:hsweb.fast-bean-copier.backend显式指定 backendhsweb.fast-bean-copier.disable-codegen禁用 runtime codegenorg.graalvm.nativeimage.imagecode/hsweb.fast-bean-copier.native-imagereflection-accessor。缓存与 classloader 策略
FastBeanCopierSupport增加 backend cache 与动态 loader 的 volatile copier cache。reflection-accessor,避免 runtime codegen 在跨 loader/受限环境下失效。ClassDescriptions改为按 classloader 分段的强缓存GENERIC_CACHE改为强缓存FastBeanCopier.clearCache()FastBeanCopier.clearCache(ClassLoader)FastBeanCopier.DEFAULT_CONVERT兼容入口,并标记弃用。转换与兼容性补强
FastBeanCopierConverterSupport引入 conversion plan cache。测试与基准
FastBeanCopierSupportTest,覆盖:DEFAULT_CONVERT泛型集合/Map 转换兼容clearCache(ClassLoader)回收与重建FastBeanCopierBenchmarkSummary.mdFastBeanCopierJmhRunner,支持 include/forks 参数化测试结果
单元测试
mvn -pl hsweb-core -am -Dtest=FastBeanCopierSupportTest,FastBeanCopierTest -Dsurefire.failIfNoSpecifiedTests=false test结果:
33000覆盖率(本模块本次测试产物)
JaCoCo:
hsweb-core/target/site/jacoco/jacoco.xml43.74%40.25%本次关键类:
AccessorFastBeanCopierBackendline88.24%, branch87.88%FastBeanCopierSupportline78.91%, branch68.42%FastBeanCopierConverterSupportline70.33%, branch59.26%ClassLoaderScopedClassCacheline88.89%, branch75.00%FastBeanCopierBackendSelectorline77.27%, branch52.38%代表性性能结果
JMH 结果文件:
hsweb-core/target/jmh-results/fast-bean-copier.json单位
us/op,越小越好:0.1000.1020.3315.5476.4958.1250.9087.4299.5300.8571.177结论:
asm-accessor已具备默认 backend 的综合优势;仅complex bean -> bean单项上javassist仍领先。文档同步
hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierBenchmarkSummary.md兼容性与运维说明
FastBeanCopier对外 facade 保持兼容,新增 cache clear API 为增量能力。DEFAULT_CONVERT兼容入口保留,但建议后续迁移至FastBeanCopierSupport.DEFAULT_CONVERT。clearCache(loader)。已知限制 / 风险
setAccessible(true)相关集合构造与 accessor 实现。exec-maven-plugin运行 forked JMH 时仍会遇到org.openjdk.jmh.runner.ForkedMainclasspath 问题,当前基准结果以 non-forked 相对对比为主。