← All issues

[JSC] Walk star-export graph once when building a module namespace

66c577c

Source/JavaScriptCore/runtime/AbstractModuleRecord.h

+(JSC::AbstractModuleRecord::Resolution::isSameBinding const): Added.

ES module namespace는 GetModuleNamespace에 의해 구성됩니다. 이 과정에서 transitive export * 체인을 통해 도달 가능한 모든 이름을 열거해야 합니다. 명세의 ResolveExport는 재귀적으로 동작하며, 순환을 차단하기 위해 resolveSet을 인자로 전달합니다.

기존 구현은 각 이름마다 ResolveExport를 개별 호출하는 방식이었습니다. 결과적으로 star-export graph를 이름 수만큼 반복 순회하여 O(names × star-edges)의 복잡도를 가졌습니다. 새로운 구현은 graph 순회와 binding 수집을 통합합니다. 각 star edge는 한 번씩만 순회하며, 이름별 candidate set을 누적합니다. Local 또는 Namespace binding이 정확히 하나인 이름은 Resolved로 fast-path 처리됩니다. Indirect entry는 resolveExport()로 fallback하며, 서로 다른 binding이 두 개 이상인 ambiguous 이름은 제외됩니다. 약 1500개의 star edge에 걸쳐 9000개의 export를 가진 깊은 barrel module을 기준으로, 벤치마크에서 약 17배의 성능 향상이 측정되었습니다.

핵심 명세 알고리즘을 fast path 기반으로 재구성한 변경입니다. 이 fast path의 정확성은 binding 고유성과 shadow rule에 관한 비자명한 불변식에 의존하며, 명세 동작에서 미묘하게 이탈할 가능성이 있는 전형적인 변경 유형에 해당합니다.

🔒

The new fast path's correctness rests on several subtle invariants — edge cases in the graph walk and binding equivalence logic are worth security investigation.

더 확인하려면 구독해 주세요