-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Slow editing in React Native codebase #37763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@amcasey do you have that version of the compiler that can print out how many types a given statement is generating? |
@DanielRosenwasser I'm planning to create a PR for an productized version of this, but the rough version is here: #37417 It dumps a csv to stdout. |
Thank you guys for posting my issue here. I'm sorry I've originally posted it in the roadmap. The issue I have might be related to how my codebase is organized or how big it is (it has 890 ts/tsx files). Let me know if I can provide any additional input / prepare some logs (if so what exactly would be useful for you and how can I collect it). I'd prefer to not give you access to the full repo as it's a private project. I'm also opened to have some session with you showing anything you'd want to see about it. Some insights:
It works like I have Then in
export function createAsyncStorage<T>(storageKey: string) {
// here I've got get/set methods that will cast JSON in storage to T type
return {
get() {
return asyncStorage.get() as T;
}
}
}
// then in the app in many places I do something like
export const someStorage = createAsyncStorage<{foo: string, bar: number}>('baz');
// than in other place in the app I import it and use typed version
someStorage.get().bar // typed as number properly |
@pie6k Thanks for the details! We have a few avenues we can pursue for figuring out what's taking so long.
If you normally use an incremental build, please be sure to clean before gathering any of the above. |
I've managed to get some error info I was trying to get auto-import suggestions for
|
About the flags you've mentioned @amcasey - I'm not compiling the code myself as React-Native uses a metro compiler. So I don't have direct control about starting ts-server probably. Can I include those flags to the VS Code typescript engine somehow? (I've tried to enable it in my vs code settings but it seems there is no such option). So in general - I never compile TS 'myself'. My issues are solely related to editing experience in my ide typescript engine (VS Code). I'm not sure where can I enable those flags eg. Running TSC on my files (with noEmit) gives
I'm attaching CPU profile for I've also run CSV tool, it's hard for me to have some solid insights from it - I've got 10280 rows, but only around ~~200 of first ones have deltas bigger than 100 I'm not sure if there is some way that would help me analyze those stats to eg. divide operations by category or detect some operation that is repeating all the time. Number one element is this: const Animator = styled(Animated.View)`
z-index: 2;
flex-grow: 1;
`; where seems like eg. (note I'm totally guessing here) If I write function foo() {
return <Animated.View style={{
height: new Animated.Value(100),
}} />
} I actually don't need to have all types of possible style properties compiled by TS, I only need to validate that Same with autosuggestions - if I want to add another style property - the first thing that is interesting for me is the name of this property - eg. opacity. If I type 'opa' - I see 'opacity' in the dropdown and this is the moment when the type of this property starts to be meaningful for me. I also don't really care about types of other (even auto-suggested) interface properties until I highlight them. Again, this is just guessing - I have no idea how it actually works under the hood. |
Thanks for the call stack - that's #32853 (which is woefully out of date - we're getting a lot more hits now). I don't suppose you can share a code fragment that reproduces the issue? We've had trouble figuring out how it could happen. Regarding switches, I'm sorry for being unclear - all of my suggestions were for command line builds because that was top-of-mind from my recent investigations. In any case, command line build stats tend to tell us useful things about the project that apply to the editor as well. I'm still looking at the perf data you've supplied - I'll reply to that separately. |
FWIW, I suspect your auto-complete woes are separate from any perf problems you're seeing (except insofar as one library may prove to trigger both). What other slowness are you seeing? Completions? Go-to-definition? Spinning "Initializing Project" in the status bar? |
The first row in the CSV is basically guaranteed to be large, because it'll cause a bunch of library types to be created. Other than that, we're looking for a few rows with big deltas and a lot of rows with little deltas. As you've suggested, probably only the top five are interesting. In this case, it sounds like they'll all point at TSX elements, probably ones using StyledComponents and/or React Native. I think you might already be using TypeScript@next, but you may want to try refreshing to pick up this change: #37749. There's already laziness around instantiating mapped types (frequently used in StyledComponents), but I can look into being even lazier. My guess is that structural type comparisons will almost immediately require the full type to be instantiated. Still looking at the profile... |
I don't see anything in the CPU profile that jumps out as different from a normal StyledComponents slowdown - if anything, less time is spent in JSX overload resolution than I would expect. |
Okay, I confirmed with someone more knowledgeable that we're already computing property types lazily, so that's probably not the issue. |
Doesn't seem like we managed to get anywhere else with this. We'll need an up-to-date repro to investigate further - please open a separate issue. |
Hello TS Team!
I appreciate your efforts to improve typescript performance! I'm very happy using TS, but as my project (react native) grew performance started to fall so badly, that it's the biggest factor impacting my productivity.
I have to reset TS server ~every 30 minutes (I'm using VS Code), quite frequently more often than that. Autocomplete with auto-import often works in a weird way - it properly suggests a variable name, but when I use it - it's not importing needed module. Sometimes I have to CMD+Space to see import suggestions, but sometimes it does not work and I have to manually write imports. Often autosuggestions start to work so slowly (3-10s) that it becomes unusable.
I'd like to help you by providing some feedback, but I actually don't know how to collect needed data. I've tried to enable verbose logs, but I'm getting a huge amount of logs (often more than 50mb) which includes so much noise, that I actually have no idea what is going on.
It would be very useful to have some sort of guide related to actually detecting and narrowing down issues with the ts server. It would be awesome to have some 'smart' diagnostics tool that would be able to tell something like 'this module types took 80% of time needed for suggestions collection caused by your last CMD+space'
I'm open to having some sessions with you trying to reproduce the issue. I don't have any specific scenario. Sometimes it works just fine for 2 hours after restarting TS server and sometimes I have to restart it every 10 minutes so I'm worried I'll waste your time if I'll not be able to reproduce it. If you're interested, however - I'd be more than happy to help as much as I can.
Screen Recording 2020-04-02 at 10.44.43 PM.mov.zip
I'm sending screen recording with issue - when I'm typing - it suggest proper variable name I can import, but when I use it - it's not actually imported. I have to CMD+Space at the end of it again to make VS Code suggest me to import given variable
Originally posted by @pie6k in #33118 (comment)
The text was updated successfully, but these errors were encountered: