Skip to content

Commit 87e7db8

Browse files
jderegclaude
andcommitted
Optimize ParameterizedTypeImpl.getActualTypeArguments: remove defensive clone
Return direct reference to internal array instead of cloning on every call. Callers read elements but do not modify the array, so cloning is unnecessary. This optimization targets a hot spot from JFR profiling: TypeUtilities ParameterizedTypeImpl.getActualTypeArguments accounted for 320 samples (39 percent of all getActualTypeArguments calls). The constructor still clones the input array to prevent external modification. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1521562 commit 87e7db8

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/com/cedarsoftware/util/TypeUtilities.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ public ParameterizedTypeImpl(Class<?> raw, Type[] args, Type owner) {
501501

502502
@Override
503503
public Type[] getActualTypeArguments() {
504-
return args.clone();
504+
// Return direct reference for performance - callers should not modify
505+
return args;
505506
}
506507

507508
@Override

0 commit comments

Comments
 (0)