tq: make Add() accept new items during batch processing #2483
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.
This pull request teaches
tq.(*TransferQueue).Add()to accept new items into theq.incomingqueue of items while a batch is processing.This is done to improve the performance of the 'delay' filter capability (see: #2466 for more). Prior to this pull request, a delayed checkout was performed like:
This means that we are doing nothing for however long it takes for Git to tell LFS about an entry in the checkout while a batch is processing.
Instead, accept new items while a batch is processing and save the time that it takes for Git to tell LFS about new items in the checkout. To do so, we keep a secondary batch called "pending", which is appended to from the
<-q.incomingchannel while a batch is processing. When a batch finishes processing, the union of "next" and "pending" are taken, with the first 100 elements becoming the next batch, and the rest are given back to "pending". This process repeats itself until there are no items remaining.In #1758, I said that the benefit to having
Add()be a blocking operation until an item was accepted into a new batch was:This statement is no longer true, since the amount of memory required per object is negligible as compared to the
tqpackage as it was prior to #1758./cc @git-lfs/core
/cc #2466