]> Cypherpunks.ru repositories - gostls13.git/commit
go/token: use atomics not Mutex for last file cache
authorAlan Donovan <adonovan@google.com>
Wed, 29 Jun 2022 17:08:11 +0000 (13:08 -0400)
committerAlan Donovan <adonovan@google.com>
Wed, 29 Jun 2022 22:19:48 +0000 (22:19 +0000)
commit0750107074c39f7b846515de47c2857cbdb7e3d6
tree5abfa8b87b4696ec40deab1e544048ee5173ee8e
parente5017a93fcde94f09836200bca55324af037ee5f
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>
src/go/token/position.go
src/go/token/serialize.go