microsoft / microsoft/TypeScript

Idea: Can we cache the result of `typeToTypeNode`?

Open
#44,043 3 comments 0 reactions 1 assignee View on GitHub

@weswigham is already working on this.

Since Nov 3, 2021.

Domain: Performance Rescheduled
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

A large percentage of declaration emit time (and a small percentage of check time) is spent in typeToTypeNode and tracing indicates that it is called on some types many times (hundreds or thousands in a sufficiently large project). I suspect, but have been able to demonstrate, that those requiring a import() qualification are particularly expensive. Could we cache the result? Two clear obstacles:

  1. Nodes are mutated during emit, so we'd need to clone anything retrieved from the cache. I'm reasonably confident that cloning will be cheaper than recomputing.
  2. typeToTypeNode takes a complex context argument. Possible workarounds include including the context hash in the cache key and storing the cached value on the context.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.