microsoft / microsoft/TypeScript

Use a data object instead of function closures for oldPrograms

Offen
#37,793 1 Kommentar 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es werden keine Dateien oder Tests genannt. Beginne damit, die Einstiegspunkte oldProgram und createProgram nachzuverfolgen, und lies anschließend Issue #37701 sowie die hier beschriebenen Anforderungen an structured clone. Als abgeschlossen gilt die Ersetzung der auf Closures basierenden zwischengespeicherten Daten durch ein rehydrierbares OldProgram, wobei die Wiederverwendung erhalten bleibt und sein Speicherbedarf reduziert wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers, performance
Issue-Typ
Refactoring
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.