Skip to content

Path mappings parsing uses too much memory for projects with many references and paths #63997

Description

@auvred

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

Reproduction:

  1. Clone the kibana repo

    cd /tmp
    git clone --depth https://github.com/elastic/kibana
    cd kibana
    yarn
    yarn kbn bootstrap
    code .
  2. Generate typecheck tsconfigs:

    node scripts/type_check.js

    Don't wait for the script to finish.
    Once you see info starting [tsc] > node_modules/typescript-7/bin/tsc -b tsconfig.refs.json --builders 6 --checkers 3 --pretty in output, you can ctrl-c it.

  3. Put "js/ts.customConfigFileName": "tsconfig.type_check.json", into .vscode/settings.json

  4. Open src/core/packages/chrome/browser/src/nav_links.ts

  5. Locate category?: AppCategory and request Find All References on category

  6. Run Developer: TypeScript: Save Heap Profile

  7. Open alloc_space flamegraph

Image

For projects like Kibana with a lot of compilerOptions.paths, allocating ParsedPatterns for every module resolution consumes too much memory.

func TryParsePatterns(pathMappings *collections.OrderedMap[string, []string]) *ParsedPatterns {
paths := pathMappings.Keys()
numPatterns := 0
for path := range paths {
if pattern := core.TryParsePattern(path); pattern.IsValid() && pattern.StarIndex == -1 {
numPatterns++
}
}
numMatchables := pathMappings.Size() - numPatterns
var patterns []core.Pattern
var matchableStringSet collections.Set[string]
if numPatterns != 0 {
patterns = make([]core.Pattern, 0, numPatterns)
}
if numMatchables != 0 {
matchableStringSet = *collections.NewSetWithSizeHint[string](numMatchables)
}
for path := range paths {
if pattern := core.TryParsePattern(path); pattern.IsValid() {
if pattern.StarIndex == -1 {
matchableStringSet.Add(path)
} else {
patterns = append(patterns, pattern)
}
}
}
return &ParsedPatterns{
matchableStringSet: matchableStringSet,
patterns: patterns,
}
}

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions