Skip to content

Commit e87e5b3

Browse files
committed
pre-size package type info maps
1 parent 0c14164 commit e87e5b3

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

internal/packages/load.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,26 @@ func loadPackageEx(dedup Deduper, ld *loader, lpkg *loaderPackage) {
346346
return
347347
}
348348

349+
typeInfoCap := len(lpkg.Syntax) * 1024
350+
if typeInfoCap < 16 {
351+
typeInfoCap = 16
352+
}
353+
identCap := typeInfoCap / 2
354+
if identCap < 16 {
355+
identCap = 16
356+
}
357+
smallCap := len(lpkg.Syntax) * 8
358+
if smallCap < 4 {
359+
smallCap = 4
360+
}
349361
lpkg.TypesInfo = &types.Info{
350-
Types: make(map[ast.Expr]types.TypeAndValue),
351-
Defs: make(map[*ast.Ident]types.Object),
352-
Uses: make(map[*ast.Ident]types.Object),
353-
Implicits: make(map[ast.Node]types.Object),
354-
Instances: make(map[*ast.Ident]types.Instance),
355-
Scopes: make(map[ast.Node]*types.Scope),
356-
Selections: make(map[*ast.SelectorExpr]*types.Selection),
362+
Types: make(map[ast.Expr]types.TypeAndValue, typeInfoCap),
363+
Defs: make(map[*ast.Ident]types.Object, identCap),
364+
Uses: make(map[*ast.Ident]types.Object, identCap),
365+
Implicits: make(map[ast.Node]types.Object, smallCap),
366+
Instances: make(map[*ast.Ident]types.Instance, smallCap),
367+
Scopes: make(map[ast.Node]*types.Scope, smallCap),
368+
Selections: make(map[*ast.SelectorExpr]*types.Selection, smallCap),
357369
}
358370
lpkg.TypesSizes = ld.sizes
359371

0 commit comments

Comments
 (0)