From e0b04fa508d6117f217a25e1868740a6a39d5605 Mon Sep 17 00:00:00 2001 From: Shahar Kohanim Date: Mon, 29 Feb 2016 12:19:26 +0200 Subject: [PATCH] cmd/link: Preallocate Lsym map Preallocate ~2MB for Lsym map (size calculation from http://play.golang.org/p/9L7F5naXRr). Reduces best of 10 link time of cmd/go by ~4%. On cmd/go max resident size unaffected, on println hello world max resident size grows by 4mb from 18mb->22mb. Performance improves in both cases. tip: real 0m1.283s user 0m1.502s sys 0m0.144s this: real 0m1.341s user 0m1.598s sys 0m0.136s Change-Id: I4a95e45fe552f1f64f53e868421b9f45a34f8b96 Reviewed-on: https://go-review.googlesource.com/19979 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: David Crawshaw --- src/cmd/link/internal/ld/sym.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/sym.go b/src/cmd/link/internal/ld/sym.go index 6122b85298b..099243442b6 100644 --- a/src/cmd/link/internal/ld/sym.go +++ b/src/cmd/link/internal/ld/sym.go @@ -58,7 +58,8 @@ var headers = []struct { func linknew(arch *LinkArch) *Link { ctxt := new(Link) - ctxt.Hash = make(map[symVer]*LSym) + // Preallocate about 2mb for hash + ctxt.Hash = make(map[symVer]*LSym, 100000) ctxt.Arch = arch ctxt.Version = obj.HistVersion ctxt.Goroot = obj.Getgoroot()