본문 바로가기
Backend2026년 6월 3일3분 읽기

Python 3.13 free-threaded — GIL 제거 실측 12주

YS
김영삼
조회 501
Python 3.13 free-threaded — GIL 제거 실측 12주

핵심 요약

Python 3.13의 free-threaded build(--disable-gil) production 12주. CPU-bound 워크로드(이미지 처리, 데이터 변환) 6.4배 빨라짐, 라이브러리 호환 70%, 미호환 30%는 C extension 재컴파일 필요. 한정 워크로드만 도입.

1. 활성화

# Python 3.13t 빌드 설치 (free-threaded)
./configure --disable-gil --enable-experimental-jit
make -j install
# 환경변수
PYTHON_GIL=0 python3.13t script.py

2. CPU-bound 실측 — 이미지 처리 1000장

from concurrent.futures import ThreadPoolExecutor
from PIL import Image
def process(path):
    img = Image.open(path).resize((800, 600))
    img.save(f'out/{path.name}')
with ThreadPoolExecutor(max_workers=8) as ex:
    list(ex.map(process, paths))
환경TimeCPU 사용률
3.13 GIL ON, 8 threads28.4s14% (단일 코어 위주)
3.13t GIL OFF, 8 threads4.4s98% (8코어 균등)
multiprocessing 86.2s82%

3. 라이브러리 호환 — 2026.6 기준

  • ✅ numpy 2.2, pandas 2.4, requests, FastAPI, SQLAlchemy 2.0+
  • ⚠️ pillow 11+ (recompile 필요), opencv 4.10+
  • ❌ TensorFlow 2.x (2027 예정), 일부 ML 라이브러리

4. I/O-bound 효과

asyncio 워크로드는 GIL 영향 작아서 4~8% 정도 개선만. CPU-bound가 진짜 이득.

5. 함정

  • Race condition — GIL이 보장하던 atomic 동작이 깨짐, dict mutation 같은 코드 lock 필요
  • Single-thread workload — GIL 없어서 lock acquire 오버헤드로 미세 -8% 느려짐
  • C extension 호환 — Py_BEGIN_ALLOW_THREADS 가정한 코드 깨짐, recompile + 검증
  • Deployment — 3.13 GIL과 3.13t No-GIL 별도 binary, CI/CD에서 명시

댓글 0

아직 댓글이 없습니다.
Ctrl+Enter로 등록