-
Notifications
You must be signed in to change notification settings - Fork 925
[experimental] Speed up Typescript without reducing overloads in json-rpc-types #1682
Comments
The biggest issue I see is that The problem that you're trying to solve is that if a functions is of the type:
You want the following result:
and not
I'll need some help actually testing these changes, but I wonder if something like this would work: type PendingRpcRequestBuilder<TOverloadedMethod> =
TOverloadedMethod extends { (...args: infer A): infer R } & infer Rest
? { (...args: A): PendingRpcRequest<R> } & PendingRpcRequestBuilder<Rest>
: TOverloadedMethod;
type PendingRpcSubscriptionBuilder<TOverloadedMethod> =
TOverloadedMethod extends { (...args: infer A): infer R } & infer Rest
? { (...args: A): PendingRpcSubscription<R> } & PendingRpcSubscriptionBuilder<Rest>
: TOverloadedMethod; These types should do what is intended, but that really depends on how TS infers the If this works, it removes the need for a bunch of indirection where:
I'm not sure how to test my changes so could you try it on your end? |
Hey @nmn thanks for the suggestion! Unfortunately it doesn't seem to be working I tested it by updating those types in I get errors showing that functions on
And similar errors when I typecheck eg
|
Thanks for the steps to test, I needed that. Perhaps the "Rest" is not getting inferred correctly. I have one more idea that does less than this does. Let me see if that helps. |
I took a crack at this today from the perspective of caching rather than speed. I don't mind it being slow; what I mind is that it seems to do a full recheck on every keystroke, and I don't know why. Here's a realtime screencast of me typing a period, deleting it, then typing it again. Screen.Recording.2023-10-20.at.10.04.48.PM.movThat's >15s per keystroke to get Intellisense. I'd be fine with that taking 15s once, and then being instant from then onward. |
🎉 This issue has been resolved in version 1.87.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Because there has been no activity on this issue for 7 days since it was closed, it has been automatically locked. Please open a new issue if it requires a follow up. |
Overview
The new RPC API uses function overloading liberally to describe the different outputs you can get from the RPC depending on the inputs you supply. You can inspect these utility types here.
Steps to reproduce
pnpm compile
chrome://tracing
for more detailDescription of bug
Typechecking, and thereby autocomplete, has slowed precipitously as a result of recursion in the checker. If you cut these overloads in half, you get a ~30x speedup.
Without reducing the number of overloads (we need them for methods like
getAccountInfo
) speed up the typechecker by making the types more efficient.Required reading: https://github.com/microsoft/TypeScript/wiki/Performance
The text was updated successfully, but these errors were encountered: