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

Regex performance on typeResolver #1746

Open
pabloalvim opened this issue Jan 30, 2025 · 1 comment
Open

Regex performance on typeResolver #1746

pabloalvim opened this issue Jan 30, 2025 · 1 comment

Comments

@pabloalvim
Copy link

We've been noticing that in our project, whenever we add a derived type (with Omit, Pick and so on), tsoa hangs or takes a long time to generate the specs.

While digging into it, I found out that the culprit was the contextualizedName method on typeResolver.ts. It contains a few Regexes with nested quantifiers. Depending on the type name, it can take up to a few minutes for each replace operation to finish.

Changing the method to use a regex with word boundaries, though, fixed the issue:

  private contextualizedName(name: string): string {
    return Object.entries(this.context).reduce((acc, [key, entry]) =>
      acc.replace(new RegExp(`\\b(${key})\\b`, 'g'), `${entry.getText()}`), name);
  }

If you're willing to try it I can open a PR. But right now we're still stuck with v5 because of a few duplicated typenames. I'd also like to open a PR for v5, but it doesn't seem there's a support branch on this repo. How should I proceed?

Anyways, thank you in advance and congratulations for the great work on tsoa!

Copy link

Hello there pabloalvim 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

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

1 participant