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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add RFC for improving Vrl performance #9812
chore: Add RFC for improving Vrl performance #9812
Changes from all commits
f9e015c
c139edc
894a0a5
327b491
5d73292
68587f9
637bfca
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a tangent, I wonder if we should investigate changing this part of the runtime to take ownership of the Event, instead of taking a mutable reference.
It seems to me that since the transform gets ownership of the event, we should pass that ownership on to the runtime so that it can optimize value access by taking actual values out of the hashmap, instead of cloning them.
This would avoid the initial clone (we still need reference counting for when more than one expression needs access to the value).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why an
Rc
and not aCow
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is because it needs to be owned in multiple places, and
Cow
is more accurately "copy-on-own" (which can then "write" to the owned copy). See for example assignment:vector/lib/vrl/compiler/src/expression/assignment.rs
Lines 367 to 371 in 4db23b3
That
value
needs to be retained in the source, inserted into the target, and returned, requiring aclone
(or even two, with one implicit inexpr.resolve
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would the advantages of a
Cow
be? I can think mutation would be safer since it copies rather than panics. Anything else?@bruceg is on the mark, ownership gets complicated. Ultimately the event store should own all the data, but the data is not always created there, it is often created in an expression and then added to the event store - sometimes whilst also passing it somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there's no advantages but this might be worthwhile spelling out in an alternatives section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the advantage of a
Cow
would be to avoid the heap allocation and reference count machinations, reducing indirection and increasing performance, since the only time it would get cloned is when it actually has to. The only way I could see to make this work is to pass in the return buffer as amut
parameter somehow instead of returning it, but I have no idea what other issues that would raise.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that we do very little actual mutation of individual values seems very important. Would it be feasible to eliminate it (and the
RefCell
) entirely? The fact that we're currently cloning those values implies that we're already not sharing mutations, unless I'm misunderstanding something.A related idea (maybe off the mark, but wanted to mention) would be to keep the actual values in our "working set" in a single place (maybe just a
HashMap
, maybe something fancier like a slotmap) and pass aroundCopy
indexes/keys into that structure. Then we can lazily read through to the actual event to fill it, replace values wholesale during execution (as opposed to mutation), and apply changes to the actual event at the end (similar to what you mentioned elsewhere).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I like dropping
Send + Sync
from remap. It pins it as single-threaded -- good -- and allows us to do extra tricks at the topology level.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ultimate reason Vrl needs
Send + Sync
is because it needs to store theProgram
in the transform and theFunctionTransform
trait needsSend + Sync
. Is there a way around that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, I meant to say I was pro the removal of
Send + Sync
fromValue
and not remap generally.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to give some examples on what we should watch out for.
I would probably favour having a wrapper type that only exposes
try_borrow
, and having the error implementExpressionError
, so that we avoid panicking Vector in production.Thinking about this, given that VRL functions return new values instead of mutated ones, do we have a list of places we'd need to
borrow_mut
? If those are minimally required, we could keep that API internal to the compiler, to avoid exposing it to functions and thus significantly reducing the risk of errors.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are not many places where we do need to
borrow_mut
- mostly in theTarget
implementation. I think any panics would be indicative of a bug, so I think we should probably fail hard and make sure the bugs aren't there by testing rigorously.