Skip to content

Commit 7860c84

Browse files
authored
Share location type strings in memory (#2947)
Memoize location documentation strings to make sure descriptions for equal types in a single summary are shared in memory. Motivated by usethesource/rascal-language-servers#1202, @DavyLandman and I did an inspection of memory use in Rascal LSP. There are many duplicate strings in summaries.
1 parent 79680e7 commit 7860c84

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

  • src/org/rascalmpl/compiler/lang/rascalcore/check

‎src/org/rascalmpl/compiler/lang/rascalcore/check/Summary.rsc‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,13 @@ data ModuleSummary =
6868
map[loc def, str synopsis] synopses = (),
6969
map[loc def, loc docLoc] docLocs = ());
7070

71-
private map[loc from, str tp] getLocationTypes(TModel tm)
72-
= (key : prettyAType(tm.specializedFacts[key] ? tm.facts[key]) | key <- tm.facts);
73-
71+
private map[loc from, str tp] getLocationTypes(TModel tm) {
72+
// Share strings in memory to reduce summary memory pressure
73+
@memo str cachedPrettyAType(AType tp) = prettyAType(tp);
74+
75+
return (key : cachedPrettyAType(tm.specializedFacts[key] ? tm.facts[key]) | key <- tm.facts);
76+
}
77+
7478
ModuleSummary makeSummary(TModel tm, str qualifiedModuleName) {
7579
if (!tm.usesPhysicalLocs) {
7680
tm = convertTModel2PhysicalLocs(tm);

0 commit comments

Comments
 (0)