microsoft / microsoft/TypeScript

Guidance on reducing heap usage of large typings?

Open
#37,214 12 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I maintain google/schema-dts which generates typings for schema.org JSON-LD. The generated typings are ~10k loc and involves a lot of type unions (e.g. Thing can be Organization or CreativeWork or Person or ...), and these can get pretty nested.

Compiling these works for me and the vast majority of users. But I get constant reports of JavaScript heap OOM errors from users consuming the typings. See google/schema-dts#34. I haven't been able to repro this at all, but I'm still hoping for some guidance on getting a better memory footprint for the type checker.

FYI, the .d.ts file looks something like this: https://unpkg.com/schema-dts@0.5.1/schema.d.ts

Questions (I'd take answers to any of these):

  1. Are there better strategies for writing these in a more memory friendly way? e.g. naming intermediate types, or declaring all properties in one huge object and defining respective types in terms of Pick<>?
  2. Are there any profiling tools that anyone would recommend using to track this down?
  3. any other advice is appreciated.

Unfortunately splitting the types up isn't an option (at least not obviously) because the types are deeply self referential.

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.

Research direction

Start by reviewing schema-dts#34 and the generated schema.d.ts example linked in the report. The issue names no TypeScript source entry point, reproducible project, or failing test; a useful outcome would be a confirmed reproduction and concrete guidance on memory-friendly declaration patterns or profiling.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.