Skip to content
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

TypeScript compiles too long when using omitted filter or shortcut for it #543

Closed
SecondThundeR opened this issue Mar 19, 2024 · 12 comments
Closed

Comments

@SecondThundeR
Copy link

SecondThundeR commented Mar 19, 2024

Couldn't find a close example for this in other issues, so I think it would be fine to post this. If this has already been discussed, then this issue can be closed 🤔

For some reason, tsc taking too long to compile simple example where not full form of filter notation was used, e.g. .on(":text", ...)

Steps to reproduce:

  1. Head to https://grammy.dev/guide/getting-started#getting-started-on-node-js to create simple project for NodeJS with TypeScript
  2. Insert this snippet to bot.ts
    import { Bot } from "grammy";
    
    // Create an instance of the `Bot` class and pass your bot token to it.
    const bot = new Bot(""); // <-- put your bot token between the ""
    
    // You can now register listeners on your bot object `bot`.
    // grammY will call the listeners when users send messages to your bot.
    
    // Handle the /start command.
    bot.command("start", (ctx) => ctx.reply("Welcome! Up and running."));
    // Handle other messages.
    bot.on(":text", (ctx) => ctx.reply("Got another message!"));
    
    // Now that you specified how to handle messages, you can start your bot.
    // This will connect to the Telegram servers and wait for messages.
    
    // Start the bot.
    bot.start();
  3. Run tsc or tsc --extendedDiagnostics

Expected behavior: TypeScript compiles snippet not longer than regular example or at least not for so long

Actual behavior: TypeScript taking 30-35 seconds to compile simple example with omitted filters/shortcut (was getting the same time with :contact at my project)

Diagnostics for .on("message:text", ...)

Files:                         53
Lines of Library:           36442
Lines of Definitions:       11507
Lines of TypeScript:           19
Lines of JavaScript:            0
Lines of JSON:                  0
Lines of Other:                 0
Identifiers:                50799
Symbols:                    36919
Types:                       4892
Instantiations:             65701
Memory used:               77521K
Assignability cache size:    2630
Identity cache size:           11
Subtype cache size:             0
Strict subtype cache size:      8
I/O Read time:              0.01s
Parse time:                 0.11s
ResolveModule time:         0.01s
ResolveTypeReference time:  0.00s
ResolveLibrary time:        0.00s
Program time:               0.14s
Bind time:                  0.06s
Check time:                 0.12s
transformTime time:         0.00s
commentTime time:           0.00s
I/O Write time:             0.00s
printTime time:             0.01s
Emit time:                  0.01s
Total time:                 0.33s

Diagnostics for .on(":text", ...)

Files:                           53
Lines of Library:             36442
Lines of Definitions:         11507
Lines of TypeScript:             19
Lines of JavaScript:              0
Lines of JSON:                    0
Lines of Other:                   0
Identifiers:                  50799
Symbols:                      36425
Types:                       534075
Instantiations:              246745
Memory used:               2667081K
Assignability cache size:     36069
Identity cache size:            112
Subtype cache size:               0
Strict subtype cache size:       42
I/O Read time:                0.01s
Parse time:                   0.11s
ResolveModule time:           0.01s
ResolveTypeReference time:    0.00s
ResolveLibrary time:          0.00s
Program time:                 0.14s
Bind time:                    0.05s
Check time:                  31.17s
transformTime time:           0.00s
commentTime time:             0.01s
I/O Write time:               0.00s
printTime time:               0.01s
Emit time:                    0.01s
Total time:                  31.38s

Seems that due to regex-like filter, number of types/instantiations and used memory is growing rapidly

@KnorpelSenf
Copy link
Member

Which version of TS do you use?

@SecondThundeR
Copy link
Author

SecondThundeR commented Mar 20, 2024

Which version of TS do you use?

5.4.2

Seems like Microsoft messed up with it, because on 5.3.3 it compiles fine

@KnorpelSenf
Copy link
Member

Yes, this is a regression in tsc. Did you already open an issue?

@SecondThundeR
Copy link
Author

Not yet, I'll open it unless similar issues have been opened. Then I'm sorry to bother you. Have a nice day!

@KnorpelSenf
Copy link
Member

It also seems to work fine with grammY 1.19.x and below. That means that it is related to having too many update types in grammY, which is a known problem right now. I have already narrowed it down to a minimal reproduction example that I shared among a few interested people in a different chat (https://t.me/fromdeno/31491). It will be very useful if you include the playground link in your issue. That way, people can understand why this bug happens without having to understand all the complex inner workings of grammY first.

https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBASwHY2FAZgQwMbDgVTABNNU4BvAKDhrgFdjTgB9BIgLjiToFsAjNAG5K1Wj2ABnCZgDmwAPydyccVNnBOEmFGQy4AX2G04wIglRFmq6XMUUTZi1ck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Senf
Copy link
Member

One last thing: be sure to mention that people should try the same playground with 5.4.2 and 5.3.3 and compare the reported error. Also, removing two or more properties from the interface Update fixes the issue. Those two pieces of information are crucial.

Could you leave a link to the opened issue here? :)

@SecondThundeR
Copy link
Author

Could you leave a link to the opened issue here? :)

Sure

@SecondThundeR
Copy link
Author

Tried to lookup similar issues, but only microsoft/TypeScript#53234 looked somewhat closer example of what we are facing right now. Here is my issue (hope I made it right): microsoft/TypeScript#57863

Also I removed last .on(...) example, which is not working on both versions, so devs won't be confused

@SecondThundeR
Copy link
Author

SecondThundeR commented Mar 22, 2024

upd: TypeScript team fixed and closed this issue

Not only they fixed this issue, but it seems they fixed your example at the very end (see microsoft/TypeScript#57871)

image

image


Also, now example at the top, compiles at the same time as regular filter (or even faster):

image

@KnorpelSenf
Copy link
Member

Holy fucking shit, this is big news

@KnorpelSenf
Copy link
Member

@all-contributors add @SecondThundeR for the bug report to Microsoft that uncorked further grammY updates ❤️

Copy link
Contributor

@KnorpelSenf

I've put up a pull request to add @SecondThundeR! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants