Fix builtin dockerfile frontend performance #2850
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Dockerfile frontend makes many calls to BuildOpts() function
after named build context support was added. Previously it
only did one per build. The assumption is that BuildOpts()
is fast and does not need to be cached on the caller side.
In current implementation BuildOpts() listed the workers
in a way that triggered the platform emulation check to be
triggered to with could take 50-100ms to complete what adds
up if there are many Dockerfile stages.
This commit adds caching to BuildOpts. If frontend was
loaded through an external image then it was already cached
and this issue did not appear.
The second commit disables rechecking emulators in this case even for the first attempt. This was added in #1381 but I think rechecking it with every build is not needed. I made them in separate commits in case we only want to backport the first commit.