Skip to content

Regex performance on typeResolver #1746

Open
@pabloalvim

Description

@pabloalvim

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions