go/token: use atomics not Mutex for last file cache
Previously, FileSet would cache the last *File found by a lookup,
using a full (exclusive) mutex within FileSet.File, turning a logical
read operation into an update. This was one of the largest sources
of contention in gopls. This change uses atomic load/store on the
'last' field without a mutex.
Also, in FileSet.AddFile, allocate the File outside the critical
section; all the other operations are typically cheap.
Fixes #53507
Change-Id: Ice8641650d8495b25b0428e9b9320837ff2ca7e1
Reviewed-on: https://go-review.googlesource.com/c/go/+/411909 Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>