← All issues

[JSC] Implement `%RegExpStringIteratorPrototype%.next` in C++

1452a43

JSC의 DFG와 FTL 계층은 자주 호출되는 builtin을 first-class IR 노드로 inline 처리하여, 컴파일러가 타입을 추론하고 JS 호출 오버헤드를 제거할 수 있도록 합니다. "primordial exec" guard는 watchpoint입니다. RegExp.prototype.exec가 여전히 원래의 native 구현으로 유지되고 있는 경우, fast path는 observable JS exec 호출을 우회하여 execInline을 직접 호출합니다. exec가 한 번이라도 교체되면, 호출 지점이 이미 상위 계층으로 올라간 뒤 반복 도중에 교체가 발생하더라도 watchpoint가 발동하고, JSC는 slow path로 OSR-exit해야 합니다.

JSTests/stress/regexp-string-iterator-next-adversarial.js

+ class Species extends RegExp {
+ static get [Symbol.species]() {
+ return function (p, f) {
+ matcher = new RegExp(p, f);
+ if (configure)
+ configure(matcher);
+ return matcher;
+ };
+ }
+ }

이 commit은 %RegExpStringIteratorPrototype%.next를 JavaScript builtin(현재 삭제됨)에서 native C++ 구현으로 전환합니다. 새로운 RegExpStringIteratorNext DFG 노드가 추가되었으며, DFG와 FTL 계층 모두에서 inline으로 컴파일됩니다. 반복 대상 RegExp에 primordial exec가 유지되는 경우, fast path를 통해 RegExpObject::execInline을 직접 호출합니다.

이제 모든 String.prototype.matchAll 루프는 watchpoint로 fast/slow 분기가 제어되는 새로운 JIT-inlined C++ hot path를 거칩니다. matchAll 벤치마크에서 최대 약 19%의 처리량 향상이 측정되었습니다.

🔒

New DFG/FTL inline node with watchpoint-gated fast path and inlined object allocation — several edge cases in the fast/slow path transitions are worth investigation.

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