Skip to content

Commit 714080a

Browse files
committed
perf(domain): ComparableValueObject cross-type 비교에서 string interpolation 제거
CompareTo의 cross-type fallback 경로(line 41)가 \$\"{thisType}\"·\$\"{otherType}\" 패턴을 사용. .NET 6+ C# 컴파일러는 단일 expression interpolation도 DefaultInterpolatedStringHandler를 거쳐 새 string 인스턴스를 heap에 할당 (thisType.ToString() 호출 + char buffer 복사 + new string). thisType.FullName 직접 사용으로 변경: - RuntimeType의 cached field 직접 반환 (lazy 1회 후 ~1ns) - 새 string 할당 0 (cached string 재사용) - string.Compare(string?, string?, ...)가 nullable 자동 처리 → 안전 - closed type(인스턴스에서 얻은 type)에서 FullName == ToString() → behavior 동일 호출 빈도 분석: - 일반 비교(같은 type)는 line 41 미실행 → 영향 없음 - Cross-type 비교는 unusual 시나리오(SortedSet에 다양한 VO 타입 섞기 등) 로 자주 발생 안 함 - production hot path 아니지만 변경 비용 0에 가까움 + heap 할당 2개 영구 제거 + 코드 명확성 향상 검증: Functorium.slnx 빌드 0 오류, 1556/1584 테스트 통과(28 skip). Behavior 변화 없음(FullName == ToString in closed type, 모든 ValueObject 인스턴스 케이스).
1 parent 8eb06ae commit 714080a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Src/Functorium/Domains/ValueObjects/ComparableValueObject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public virtual int CompareTo(ComparableValueObject? other)
3838
Type thisType = GetUnproxiedType(this);
3939
Type otherType = GetUnproxiedType(other);
4040
if (thisType != otherType)
41-
return string.Compare($"{thisType}", $"{otherType}", StringComparison.Ordinal);
41+
return string.Compare(thisType.FullName, otherType.FullName, StringComparison.Ordinal);
4242

4343
return GetComparableEqualityComponents()
4444
.Zip(other.GetComparableEqualityComponents(),

0 commit comments

Comments
 (0)