AnnotationUtil新增两级缓存架构,提升高频注解解析性能(pr#1434@Gitee)

This commit is contained in:
Looly
2026-03-19 15:47:13 +08:00
parent 21a68690ee
commit d5dac7cd51
2 changed files with 5 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.45
# 5.8.45(2026-03-19)
### 🐣新特性
* 【core 】 `AnnotationUtil`新增两级缓存架构提升高频注解解析性能pr#1434@Gitee
### 🐞Bug修复

View File

@@ -9,10 +9,9 @@ import cn.hutool.core.exceptions.UtilException;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.func.Func1;
import cn.hutool.core.lang.func.LambdaUtil;
import cn.hutool.core.map.WeakConcurrentMap;
import cn.hutool.core.map.reference.WeakKeyConcurrentMap;
import cn.hutool.core.util.*;
import java.lang.annotation.*;
import java.lang.invoke.SerializedLambda;
import java.lang.reflect.AnnotatedElement;
@@ -58,14 +57,14 @@ public class AnnotationUtil {
* 键:注解查询键(被注解元素 + 目标注解类型)<br>
* 值原生注解对象或NULL_ANNOTATION_SENTINEL表示不存在
*/
private static final WeakConcurrentMap<AnnotationLookupKey, Annotation> L1_ANNOTATION_CACHE = new WeakConcurrentMap<>();
private static final WeakKeyConcurrentMap<AnnotationLookupKey, Annotation> L1_ANNOTATION_CACHE = new WeakKeyConcurrentMap<>();
/**
* L2 合成注解缓存(别名/聚合场景)<br>
* 键:注解查询键(被注解元素 + 目标注解类型)<br>
* 值合成注解对象或NULL_ANNOTATION_SENTINEL表示不存在
*/
private static final WeakConcurrentMap<AnnotationLookupKey, Annotation> L2_SYNTHESIZED_ANNOTATION_CACHE = new WeakConcurrentMap<>();
private static final WeakKeyConcurrentMap<AnnotationLookupKey, Annotation> L2_SYNTHESIZED_ANNOTATION_CACHE = new WeakKeyConcurrentMap<>();
/**
* 注解查询缓存键,唯一标识一次注解查询操作