tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

Regex performance on typeResolver

Open pabloalvim opened this issue 11 months ago • 2 comments

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!

pabloalvim avatar Jan 30 '25 12:01 pabloalvim

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.👀

github-actions[bot] avatar Jan 30 '25 12:01 github-actions[bot]

Hey @pabloalvim!

You're correct, contextualizedName was completely removed as of v6.0.0.

I'm not really a developer for TSOA (just here due to a separate issue), but maybe provide more details as to why you can't upgrade.. That sounds like a bigger issue.

CodeSmith32 avatar Feb 10 '25 15:02 CodeSmith32

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Jul 11 '25 00:07 github-actions[bot]