Summary#
성능 문제는 알고리즘보다도 상태를 어디에 두고 얼마나 오래 살리는지에서 자주 발생한다. 공통으로 재사용되는 리소스는 상위 범위로 올려 중복 생성을 없애고, 드물게 쓰이는 선택적 상태는 지연 할당해 기본 비용을 줄이는 것이 효과적이다. 반대로 분석용 임시 상태를 전역에 붙잡아 두면 메모리 폭증과 예측 불가능한 상호작용이 생긴다.
Problem#
스레드 풀, 콜백 저장소, 압력 추적기, 대형 테스트 체크포인트 같은 무거운 상태를 인스턴스마다 들고 있거나 필요 이상 오래 유지해 메모리와 CPU를 낭비한다.
Solution#
실제 공유가 필요한 경계에서만 상태를 공유하고, optional 상태는 lazy allocation으로 전환하며, 일회성 분석 상태는 지역화한다. 테스트 자산도 가능한 한 작은 동등물로 바꿔 비용을 낮춘다.
Failure Modes#
- 전역/장수명 맵이 큰 모듈 전체 크기에 비례해 메모리를 잡아먹음
- 항상 null인 콜백까지 기본 비용으로 들고 다님
- 과도한 공유로 가변 상태 경합이나 수명 관리 버그가 새로 생김
- 너무 작은 테스트 fixture로 실제 동작과의 차이를 키움
Sources#
- https://github.com/tensorflow/tensorflow/pull/122996
- https://github.com/tensorflow/tensorflow/pull/122994
- https://github.com/tensorflow/tensorflow/pull/122933
- https://github.com/tensorflow/tensorflow/pull/122848
- https://github.com/tensorflow/tensorflow/pull/122990
- https://github.com/tensorflow/tensorflow/pull/120652
- https://github.com/tensorflow/tensorflow/pull/122765
- https://github.com/tensorflow/tensorflow/pull/122794
- https://github.com/tensorflow/tensorflow/pull/122827
- https://github.com/tensorflow/tensorflow/pull/122707
- https://github.com/tensorflow/tensorflow/pull/122931
- https://github.com/tensorflow/tensorflow/pull/122976
- https://github.com/huggingface/transformers/pull/47259
- https://github.com/huggingface/transformers/pull/47213
- https://github.com/huggingface/transformers/pull/47035
- https://github.com/huggingface/transformers/pull/47251
- https://github.com/huggingface/transformers/pull/45333
- https://github.com/huggingface/transformers/pull/47146
- https://github.com/huggingface/transformers/pull/47134
- https://github.com/huggingface/transformers/pull/47073
- https://github.com/huggingface/transformers/pull/47249
- https://github.com/huggingface/transformers/pull/47244
- https://github.com/huggingface/transformers/pull/47248
- https://github.com/huggingface/transformers/pull/47043
- https://github.com/microsoft/ML-For-Beginners/pull/1002
- https://github.com/microsoft/ML-For-Beginners/pull/1001
- https://github.com/microsoft/ML-For-Beginners/pull/1000
- https://github.com/microsoft/ML-For-Beginners/pull/994
- https://github.com/microsoft/ML-For-Beginners/pull/991
- https://github.com/microsoft/ML-For-Beginners/pull/990
- https://github.com/microsoft/ML-For-Beginners/pull/989
- https://github.com/microsoft/ML-For-Beginners/pull/987
- https://github.com/microsoft/ML-For-Beginners/pull/986
- https://github.com/ClickHouse/ClickHouse/pull/107924
- https://github.com/ClickHouse/ClickHouse/pull/95006
- https://github.com/ClickHouse/ClickHouse/pull/109667
- https://github.com/ClickHouse/ClickHouse/pull/108569
- https://github.com/ClickHouse/ClickHouse/pull/110088
- https://github.com/ClickHouse/ClickHouse/pull/109204
- https://github.com/ClickHouse/ClickHouse/pull/110087
- https://github.com/ClickHouse/ClickHouse/pull/110071
- https://github.com/ClickHouse/ClickHouse/pull/110056
- https://github.com/ClickHouse/ClickHouse/pull/106359
- https://github.com/ClickHouse/ClickHouse/pull/109671
- https://github.com/vercel/turborepo/pull/11952
- https://github.com/vercel/turborepo/pull/13344
- https://github.com/vercel/turborepo/pull/13342
- https://github.com/vercel/turborepo/pull/13340
- https://github.com/vercel/turborepo/pull/13339
- https://github.com/vercel/turborepo/pull/13336
- https://github.com/vercel/turborepo/pull/13338
- https://github.com/vercel/turborepo/pull/13337
- https://github.com/vercel/turborepo/pull/13335
- https://github.com/vercel/turborepo/pull/13334
- https://github.com/vercel/turborepo/pull/13328
- https://github.com/vercel/turborepo/pull/13332
- https://github.com/vercel/turborepo/pull/13331
- mined_at: 2026-07-11T21:15:05Z
Sagwan Revalidation 2026-07-11T21:52:59Z#
- verdict:
ok - note: 상태 수명·공유 범위 최적화 원칙은 최신 practice와도 부합한다.
Sagwan Revalidation 2026-07-13T16:53:28Z#
- verdict:
ok - note: 상태 수명·공유 범위 최적화 원칙은 최신 practice와 충돌 없다.
Sagwan Revalidation 2026-07-15T16:09:47Z#
- verdict:
ok - note: 상태 수명·공유 범위 원칙은 최신 practice와도 일치해 재사용 가능.
Sagwan Revalidation 2026-07-17T17:27:22Z#
- verdict:
ok - note: 상태 수명·공유 범위 최적화 권장은 현재 practice와도 부합한다.
Sagwan Revalidation 2026-07-19T18:01:05Z#
- verdict:
ok - note: 상태 수명·공유 범위 최적화 원칙은 여전히 유효하다.
Sagwan Revalidation 2026-07-21T19:21:25Z#
- verdict:
ok - note: 일반 원칙 중심이라 최근 practice와 충돌 없이 재사용 가능함