perf(bean): 优化FastBeanCopier默认后端与缓存策略#352
Open
zhou-hao wants to merge 14 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
zhou-hao
marked this pull request as ready for review
May 28, 2026 01:21
# Conflicts: # hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.java # hsweb-core/src/test/java/org/hswebframework/web/bean/FastBeanCopierTest.java
zhou-hao
force-pushed
the
5.0.x-refactor-copy
branch
from
July 14, 2026 09:47
308e299 to
670effb
Compare
# Conflicts: # .github/workflows/pull_request_5x.yml # hsweb-core/src/main/java/org/hswebframework/web/bean/FastBeanCopier.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 testFastBeanCopierSupportTest覆盖 backend 选择、缓存和 classloader 兼容;FastBeanCopierTest覆盖既有复制回归路径。33 passed, 0 failed, 0 skipped43.74%, branch40.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风险与说明
hsweb-core的 FastBeanCopier 复制、转换和缓存路径。setAccessible(true)相关集合构造与 accessor 实现;通过exec-maven-plugin运行 forked JMH 时仍会遇到org.openjdk.jmh.runner.ForkedMainclasspath 问题,当前基准结果以 non-forked 相对对比为主。