--- id: wiki-2026-0508-javascriptcore title: JavaScriptCore category: 10_Wiki/Topics status: verified canonical_id: self aliases: [JSC, WebKit JSC, Nitro] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [javascript, engine, webkit, jit] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: C++ framework: WebKit --- # JavaScriptCore ## 매 한 줄 > **"매 Apple WebKit 의 JavaScript 엔진 — 4-tier JIT pipeline (LLInt → Baseline → DFG → FTL/B3)"**. Safari, iOS WebView, React Native (Hermes 도입 전), Bun runtime의 core. 매 V8 대비 startup 빠름, peak performance 비슷 — 매 mobile-first 최적화. ## 매 핵심 ### 매 4-Tier JIT Pipeline - **LLInt** (Low-Level Interpreter): 매 첫 실행, profiling 시작. - **Baseline JIT**: 매 hot 코드 → simple machine code, type feedback 수집. - **DFG** (Data Flow Graph): 매 speculative optimization, OSR exit 가능. - **FTL** (Faster Than Light) / B3 backend: 매 최상위 tier, LLVM-style IR. ### 매 GC - **Riptide**: 매 generational + concurrent mark-and-sweep. - **Eden GC**: 매 young objects, frequent. - **Full GC**: 매 entire heap, infrequent. ### 매 응용 1. Safari / WKWebView (iOS, macOS). 2. Bun runtime — 매 Node.js 대안, JSC 채택 (V8 X). 3. React Native (legacy iOS, Hermes 이전). 4. GNOME / GTK WebKitGTK. ## 💻 패턴 ### Bun runtime — JSC embed ```javascript // bun runs JS via JSC (not V8) // startup: ~10ms vs Node ~30ms import { serve } from "bun"; serve({ port: 3000, fetch(req) { return new Response("Hello from JSC"); }, }); ``` ### Inline cache observation (JSC IR dump) ```bash # JSC bytecode dump JSC_dumpBytecodesAfterGeneration=true \ /System/Library/Frameworks/JavaScriptCore.framework/Helpers/jsc script.js # DFG/FTL 단계 확인 JSC_dumpDFGGraphAtEachPhase=true jsc script.js ``` ### Hidden class friendly object ```javascript // JSC structure (V8의 hidden class 와 동일 개념) function Point(x, y) { this.x = x; // structure transition T0 → T1 this.y = y; // T1 → T2 } // T2 가 stable → inline cache hit ``` ### Type feedback (monomorphic 유지) ```javascript function add(a, b) { return a + b; } add(1, 2); // int+int → DFG int specialization add(1.5, 2.5); // float+float → polymorphic, slower // 매 monomorphic 유지 — 매 동일 type 만 호출 ``` ### OffHeap typed array (Bun) ```javascript // JSC 의 ArrayBuffer 는 GC 외부 — large data 적합 const buf = new ArrayBuffer(1024 * 1024 * 100); // 100MB const view = new Uint8Array(buf); // 매 GC pressure X ``` ### WeakRef (JSC 1.16+) ```javascript const cache = new WeakRef(largeObject); // 매 GC 가 collect 가능 — memory pressure 시 free const ref = cache.deref(); if (ref) { /* still alive */ } ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | iOS native app + JS | JSC (WKWebView 또는 JavaScriptCore.framework) | | Cross-platform server | V8 (Node.js) — 매 ecosystem 큼 | | Fast startup CLI | Bun (JSC) — 매 startup 압도적 | | RN new architecture | Hermes — 매 mobile 최적화 | **기본값**: server는 V8/Node, mobile WebView는 JSC, fast CLI는 Bun. ## 🔗 Graph - 부모: [[WebKit]] - 변형: [[V8]] · [[Hermes]] - 응용: [[React Native]] - Adjacent: [[Garbage Collection]] ## 🤖 LLM 활용 **언제**: iOS WebView 성능 분석, Bun 코드 최적화, JSC-specific bug 진단. **언제 X**: Node.js / Chrome 환경 — 매 V8 별도 문서. ## ❌ 안티패턴 - **Polymorphic call sites**: 매 inline cache miss → DFG bailout. - **delete operator**: 매 hidden class transition 깨짐 — 매 undefined 할당으로 대체. - **arguments object 남용**: 매 modern JSC 는 rest params 가 빠름. ## 🧪 검증 / 중복 - Verified (WebKit Wiki, JSC source — github.com/WebKit/WebKit). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — JSC 4-tier pipeline + Bun 응용 |