Avoid cloning values during reduce#347
Open
petrosagg wants to merge 2 commits intoTimelyDataflow:masterfrom
Open
Avoid cloning values during reduce#347petrosagg wants to merge 2 commits intoTimelyDataflow:masterfrom
petrosagg wants to merge 2 commits intoTimelyDataflow:masterfrom
Conversation
`reduce_core` was previously forced to clone the output data before presenting it to the logic function for inspection. Simply annotating the type with a reference was not possible due to the buffer being held in the same struct as some of the data it contained, making it a self-referencial struct which the borrow checker doesn't allow. However, the only reason this buffer was held in the same struct was to reuse its allocation. This patch therefore creates a brand new vector every time we need to process data that contains references instead of cloned data. The expectation is that in the general case it's better to allocate a vector of references than clone a bunch of values. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
This patch brings back the benefits of re-using the output buffer allocation at the cost of some unsafe code reasoning. Since the buffer is always cleared after each use we can simply store its type erased pointer and temporarily bring it back to its Vec form whenever there is some processing to do. Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
61d3c9b to
3d625d2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 PR can be merged as-is or only its first commit depending on the type of trade-off we want to do:
computeis invoked. The expectation is that in most cases it makes sense to do one allocation for references than copy potentially complicated value types.