ReviewOS

also looking at this

stacks/dtsx

perf(isolated): benchmark declaration generation paths

#3106
Merged chris wants to merge codex/isolated-mode-benchmarks into main
4 files +215 -6

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

packages/dtsx/src/extractor/scanner.tsmodified+4-29
Changes to packages/dtsx/src/extractor/scanner.ts
@@ -726,9 +726,9 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
726726 /**
727727 * Skip an annotated variable initializer without capturing its text.
728728 *
729 * Unlike the general statement skipper this hot path walks each byte once
730 * and only tracks delimiters that can keep a variable initializer open.
731 * Isolated declarations call it for every explicitly annotated value.
729 * Isolated declarations call it for every explicitly annotated value. Safe
730 * single-line literals take the direct path; complex syntax falls back to
731 * the general JSX-aware statement scanner.
732732 */
733733 function skipAnnotatedVariableInitializer(): void {
734734 pos++ // skip =
@@ -756,32 +756,7 @@ function scanDeclarationsInternal(_source: string, _filename: string, _keepComme
756756 }
757757 }
758758
759 let depth = 0
760 let angleDepth = 0
761 let jsxDepth = 0
762 while (pos < len) {
763 if (skipNonCode()) continue
764 const ch = source.charCodeAt(pos)
765 if (ch === CH_LPAREN || ch === CH_LBRACE || ch === CH_LBRACKET) {
766 depth++
767 }
768 else if (ch === CH_RPAREN || ch === CH_RBRACE || ch === CH_RBRACKET) {
769 depth--
770 }
771 else if (ch === CH_LANGLE && depth === 0) {
772 const jsxDelta = jsxTagDeltaAt(pos)
773 if (jsxDelta !== null) jsxDepth = Math.max(0, jsxDepth + jsxDelta)
774 else if (pos + 1 >= len || source.charCodeAt(pos + 1) !== CH_EQUAL) angleDepth++
775 }
776 else if (ch === CH_RANGLE && depth === 0 && jsxDepth === 0 && !isArrowGT()) {
777 if (angleDepth > 0 && (pos + 1 >= len || source.charCodeAt(pos + 1) !== CH_EQUAL)) angleDepth--
778 }
779 else if (depth === 0 && angleDepth === 0 && jsxDepth === 0 && (ch === CH_SEMI || ch === CH_COMMA)) {
780 return
781 }
782 if (depth === 0 && angleDepth === 0 && jsxDepth === 0 && checkASITopLevel()) return
783 pos++
784 }
759 skipToStatementEnd()
785760 }
786761
787762 /**