Repository navigation
Conversation
…s a subtype With more than one overload, the checker first looks for a signature in a subtype pass. A JSX element is a ReactElement<any, any>, and `any` is assignable to ReactNode but not its subtype, so every Box, Flex, Text... with element children failed the subtype pass on its default overload, and the checker inferred and checked the polymorphic `as` overload and the trailing default before it took the first one in the assignability pass. The default props now type `children` as `C | JSX.Element | readonly (...)[]`, used only where `C` accepts every value of that union, so the props accept and reject the same values while JSX children match as a subtype. Large benchmark app, 20 alternating runs, medians: tsc check 107 -> 82 ms, Next's TypeScript phase 474 -> 412 ms; types 66,143 -> 36,187. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Next's TypeScript phase is slower for Devup UI apps than for Tailwind ones. This PR finds where the type-check time goes and removes the largest part of it, without changing which programs the types accept or reject.
Where the time goes
Measured with
tsc --extendedDiagnosticsand--generateTrace(TS 7) on the large benchmark app and on single-construct apps of 100 to 3,000 elements:Boxhave three overloads: the default element, the polymorphicasone (generic), and the default again. With more than one overload, the checker first tries a subtype pass. A JSX element is aReactElement<any, any>, andanyis assignable toReactNodebut not its subtype. So everyBox,Flex,Text... with element children failed the subtype pass on its default overload. The checker then inferred and checked the polymorphic overload, then the trailing default, and only took the first overload in the assignability pass. This cost about 16 extra types and 14 instantiations per element. On the large app it doubled the types the checker creates (66,143, against 36,187 once it is fixed)._hover/_groupHover... keys of the selector props (CamelCase/PascalCaseover the csstype pseudo lists), and the rest come fromMerge/Omitover the CSS properties. tsgo runs 4 checkers, and each one pays this once.StyleOrder(Range<255>) creates 35k types, but only whenstyleOrderis used.Change
The default props type
childrenasC | JSX.Element | readonly (...)[], so JSX children match the default overload as a subtype. This is used only whereC(the element's ownchildren) already accepts every value of that union, so the props accept and reject the same values on the web and on React Native.New type tests check that:
div/span/button/img/inputstay the same as before: the same keys and optionality, identical types for every prop, and the same values forchildren. This holds on the web and with the React Native augmentation.All the new tests also pass against the types on
main.Results (large benchmark app, alternating A/B runs, medians)
tscon the app project, the command Next runs: check time (20 runs)--checkers 1check time (12 runs, generated app copy)Tried and not kept
CamelCasework during warm-up. It cut 8.7k instantiations but saved only about 6% of check time, within noise. It would also mean keeping a 212-key list in sync with csstype-extra.NoInferon the polymorphic overload's props. It saved about 14% alone, and nothing on top of this change.요약
Devup UI 앱의 Next TypeScript 단계가 Tailwind 앱보다 느립니다. 이 PR은 타입 검사 시간이 어디에 쓰이는지 찾고, 타입이 받아들이거나 거부하는 프로그램을 바꾸지 않고 그중 가장 큰 부분을 없앱니다.
시간이 쓰이는 곳
대형 벤치마크 앱과 요소 100~3,000개짜리 단일 구성 앱에서
tsc --extendedDiagnostics와--generateTrace(TS 7)로 측정했습니다.Box같은 컴포넌트에는 오버로드가 셋 있습니다. 기본 요소, 다형as(제네릭), 다시 기본 요소입니다. 오버로드가 둘 이상이면 체커는 먼저 서브타입 패스를 시도합니다. JSX 요소는ReactElement<any, any>이고,any는ReactNode에 할당은 되지만 서브타입은 아닙니다. 그래서 요소 자식을 가진 모든Box,Flex,Text...가 기본 오버로드의 서브타입 패스에서 실패했습니다. 그러면 체커는 다형 오버로드를 추론·검사하고, 이어서 마지막 기본 오버로드를 검사한 뒤에야 할당 패스에서 첫 오버로드를 택했습니다. 요소마다 타입 약 16개, 인스턴스화 14개가 더 들었습니다. 대형 앱에서는 체커가 만드는 타입이 두 배가 됐습니다(수정 전 66,143개, 수정 후 36,187개)._hover/_groupHover... 키를 만드는 데 듭니다(csstype 의사 클래스 목록에 대한CamelCase/PascalCase). 나머지는 CSS 속성에 대한Merge/Omit에서 나옵니다. tsgo는 체커 4개를 돌리고, 체커마다 이 비용을 한 번씩 냅니다.StyleOrder(Range<255>)는 타입 35k개를 만들지만styleOrder를 쓸 때만입니다.변경
기본 props가
children을C | JSX.Element | readonly (...)[]로 타이핑해서, JSX 자식이 기본 오버로드에 서브타입으로 맞습니다. 요소 자신의children인C가 이 유니온의 모든 값을 이미 받는 경우에만 씁니다. 그래서 웹과 React Native에서 props가 받아들이고 거부하는 값은 그대로입니다.새 타입 테스트는 다음을 확인합니다.
div/span/button/img/input의 props가 이전과 같습니다. 키와 선택성이 같고, 모든 prop의 타입이 동일하며,children이 받는 값이 같습니다. 웹에서도, React Native 보강을 적용해도 마찬가지입니다.새 테스트는 모두
main의 타입으로도 통과합니다.결과 (대형 벤치마크 앱, A/B 교대 실행, 중앙값)
tsc(Next가 실행하는 명령) 검사 시간 (20회)--checkers 1검사 시간 (12회, 생성한 앱 사본)시도했지만 넣지 않은 것
CamelCase작업을 건너뛰려는 것이었습니다. 인스턴스화는 8.7k 줄었지만 검사 시간은 약 6%만 줄어 노이즈 범위였습니다. 게다가 212개 키 목록을 csstype-extra와 계속 맞춰야 합니다.NoInfer적용. 단독으로는 약 14% 줄었지만, 이 변경 위에서는 효과가 없었습니다.🤖 Generated with Claude Code