Closed ffMathy closed 1 month ago
What happens if we type TypedContext
as a union type of all the different types in TypedContextSubtypeMap instead?
Are the performance issues only for the intellisense, or does it also happen when you run tsc
? I'm failing to reproduce the issues in our code base.
What happens if we type
TypedContext
as a union type of all the different types in TypedContextSubtypeMap instead?
I tried this too today. Didn't work. If I then removed some of the unions (maybe 5 out of 30 or so), the performance got a little better.
Are the performance issues only for the intellisense, or does it also happen when you run
tsc
? I'm failing to reproduce the issues in our code base.
It's for both apparently. The weird thing is that if I just move my types to the TS Playground, I also can't get it to get slow. So I think it is because we are referencing TypedContext
in a lot of places in our codebase.
Performance tracing could give some further insight into what the specific performance bottlenecks are: https://github.com/microsoft/TypeScript/wiki/Performance#performance-tracing
Yeah I looked into that too. Will have to use my spare time for that though, as we are very busy these days. Might take some time, but let's leave the issue open.
If you manage to create a reproduction example I can help, but as of now it's not presenting in any of our repos.
This can be closed. Ran a full trace (allocated 24 gigabytes of RAM and ran for 6 hours - that's why I thought it was stuck), and it revealed that the issue was actually somewhere else in our own custom types, although the issue would present itself in very certain situations that would lead me to believe it was related to the given PR.
The given PR definitely made it "worse", but it's not bad at all, and was just when used in combination with our weird custom types.
That's a massive trace!
Thank you for the update.
After merging #43, performance of TypeScript itself in VS Code has dropped significantly. For our project, we are seeing up to 130 seconds before I get autocomplete suggestions from the TypeScript Language Service.
I first tried removing the strong-typing of the custom attributes again to see if that made it faster. It did not.
Then I tried changing the way the
TypedContext
union type is defined.Right now, it's defined as:
If I change it to:
Then the performance problems go away 100%, and I get instant feedback. However, then I also lose the type discrimination capability.
Example:
Can we think of a type that isn't slow for TypeScript to handle?
We have 150+ custom attributes across around maybe ~30 object types. I don't feel like the object type count is a lot. The custom attributes is a bit high, but then again, that doesn't seem to be the cause of the performance issue either way.