Skip to content

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

@SecondThundeR

Description

@SecondThundeR

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions