You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Because access to the lines and info fields of token.File are protected by the mutex of the parent FileSet, all concurrent calls to AddLine in a typical application contend for the same lock, which becomes a major bottleneck when parsing files in parallel, as done by golang.org/x/tools/go/loader for example.
Fine-grained locking, that is, an additional mutex in each token.File that protects these two fields, eliminates the bottleneck. I quickly prototyped and measured it on a realistic application, and execution time fell to 580ms from 700m, an improvement of nearly 20%.
The necessary change is straightforward except for two places:
(1) In its loop, (*FileSet).Write needs to make a copy of each File's lines and infos while holding the file's mutex.
(2) (*File).PositionFor seems to have a pre-existing data race, since it calls File.position without a lock, which calls unpack, which reads the lines and info fields.
The text was updated successfully, but these errors were encountered:
Because access to the lines and info fields of token.File are protected by the mutex of the parent FileSet, all concurrent calls to AddLine in a typical application contend for the same lock, which becomes a major bottleneck when parsing files in parallel, as done by golang.org/x/tools/go/loader for example.
Fine-grained locking, that is, an additional mutex in each token.File that protects these two fields, eliminates the bottleneck. I quickly prototyped and measured it on a realistic application, and execution time fell to 580ms from 700m, an improvement of nearly 20%.
The necessary change is straightforward except for two places:
(1) In its loop, (*FileSet).Write needs to make a copy of each File's lines and infos while holding the file's mutex.
(2) (*File).PositionFor seems to have a pre-existing data race, since it calls File.position without a lock, which calls unpack, which reads the lines and info fields.
The text was updated successfully, but these errors were encountered: