GN: Don't import a file more than once.

GN caches the results of imports so we don't have to load them more than once.
But if two BUILD files load the same import at the same time, there is a race

Previously GN would resolve the winner after the import ran on the assumption
that imports are fast and collisions are rare. But some imports run expensive
scripts meaning they take a long time and collisions are likely. The result is
that a file can get imported more than once.

This patch adds extra locking around the import to block other threads and
only do the import once.

Increase the minimum thread count for low-end systems to 8. This gives the fastest running time on an older MacBook.

Both the import change and the thread change independently speed up GN on Mac Chrome by 150-300ms, so actual improvement should be 300-600ms. On beefy Windows and Linux workstations, there seems to be no change in performance with these changes, although the import change should help some worst-case situations.

BUG=599892

Review-Url: https://codereview.chromium.org/1957483004
Cr-Original-Commit-Position: refs/heads/master@{#392353}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: a5b852cfbe6b6912ee6d1af145cbe9c090e40b42
3 files changed
tree: e42e366bf76389d00a2a7bd6fb94563d601a7bf5
  1. tools/