-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(new transform): Initial javascript
transform implementation
#721
Conversation
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
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.
This at a quick glance looks pretty good! I'd be curious to see benchmarks to compare it to the lua runtime, what do you think?
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@LucioFranco I would be interested in doing the benchmarking too. However, I expect it to be less performant than Lua because of the different model of computation: here event is copied entirely to JavaScript and then the result is copied entirely back, while in Lua fields are read and written on-demand. But I think the functional approach to processing events is more flexible for the user. |
@a-rodin agreed, I think mostly it would be helpful for documentation to express how much slower it might be. |
👍 This is awesome! Thanks for doing this.
This is perfectly fine for now. I added #706 for further discussion around this exact topic. If we keep the flattened structure (pending on #704), I'm not sure I would unflatten the event anyway. A transform, by nature, is operating on internal data structures.
That's super interesting. I'm curious what you think about the @LucioFranco? |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@a-rodin looks like we need to track the changes on master to get the tests to pass. |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@LucioFranco I've added some benchmarks, similar to the ones for Lua. The results:
The numbers for Lua:
From disabling certain parts of the code it seems like serialization to JSON in Rust + just running JS |
Some really weird things happen: edefa8f breaks one of the tests, causing stack overflow in JavaScript code. I'm not sure how can it be, but probably removing It is also interesting that the problem shows itself only on debug builds, as |
I think the problem might be caused by unsafe implementation of However, it is better to keep the initialization of the context at the creation of the transform, both for performance reasons and to allow keeping state between subsequent events. So probably a way to create a new context for each thread is needed. |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
The problem was caused by an issue in QuickJS code that checks for stack overflow exception. I've sent the patch with the fix to QuickJS mailing list and created PR theduke/quickjs-rs#19 to Rust |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Replacing eval_as to call_function in the transform code increased the performance twofold:
|
Nice! That looks comparable to the |
This looks good. @a-rodin @LucioFranco is this ready to merge? |
@binarylogic I think maybe we can wait for the next release of |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
With native creation of
|
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@a-rodin those benchmarks look quite good! I see that a lot of the js tests are failing on CI, any idea why? |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@LucioFranco The tests should be passing now. |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
This reverts commit 652fcd9. Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Noting, we can merge this if it's ready and not register it as a transform until we're ready to expose the API. We'll need to remove the docs before doing so. |
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
Signed-off-by: Alexander Rodin <rodin.alexander@gmail.com>
@Hoverbear what are your thoughts on this? Should we close it in favor of the |
Related: running QuickJS inside a wasm runtime requires quite a lot of plumbing. |
@Hoverbear bump. |
Closing this PR since it has fallen out of sync, the author is no longer working on it, and we want to understand better how it fits in with Vector. A lot has changed since this PR was opened:
All of that said, we'd like to see how the community adopts the above features before introducing more languages into Vector. Javascript is significantly worse in the performance and safety aspects than all of the offerings above. |
Description
Closes #667
This PR adds basic JavaScript transform implemented using QuickJS engine. See docs in the committed files for details.
Limitations
Date
type supports only millisecond precision, Vector's timestamps lose precision after applying any JavaScript transform. An alternative would be to not convert timestamps to JavaScript dates, but it would probably make user experience less streamlined.Unflatten
struct public or creating new specialized interfaces for it.Possible improvements that require changes in quick-js crate
JsValue
s directly, without intermediate serialization to JSON, to improve performance.In addition, if Vector supported asynchronous transformations that returned
Future
s instead of transformed values, and alsoquick-js
crate implemented support for returningPromise
s to native code, it could have been possible to implement fetch API and allow the transformations to connect to external HTTP services to enrich the events.