microsoft / microsoft/TypeScript
Use a data object instead of function closures for oldPrograms
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
structured clone algorithm, oldProgram, function closure
Suggestion
Create some transformer that transforms a Program to an OldProgram, which, instead of using function closures, would store the data, necessary for "rehydrating" a program, directly on the OldProgram object.
The createProgram function would then take a Program|OldProgram as the parameter for oldProgram.
The OldProgram object should be compatible with the structured clone algorithm, which would involve creating similar "serialized++" versions of all of the transitive objects contained in the data of OldProgram
Use Cases & Motivation
When caching a Program for use in a later compiler step, it contains many functions not consumed when taking in an oldProgram, these functions are needlessly holding variables in their closure/memory.
By trimming the methods down to only those used, the memory footprint is reduced, but they still have a memory cost of about 15MB for most of our projects (this number calcuated by observing ~2300MB freed after deleting 150 Programs from a cache). In our case this becomes ~22GB for all our projects. It would be nice to create a more lightweight version of these that can still be efficiently rehydrated for quick compiler actions.
This could also allow users in a specific use case to trim down the data more than is prudent to allow them to cache all of the Programs.
As an added bonus, if the OldProgram type could be made compatible with the structured clone algorithm, then it would be much easier to share a single, much larger, cache between a dozen-or-so compiler hosts.
As noted in #37701, compile times are slow when not able to reuse an oldProgram, this is aimed at helping users to be able to reuse an oldProgram more often.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are named. Start by tracing the oldProgram and createProgram entry points, then read issue #37701 and the structured clone requirements described here. Done means replacing closure-based cached data with a rehydratable OldProgram while preserving reuse and reducing its memory footprint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers, performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100