Skip to content
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

[Merged by Bors] - feat: introduce ByteBuf for SmartModuleSpec #2738

Conversation

EstebanBorai
Copy link
Contributor

In order to have a more performant implementation on WASM bytes, a
dedicated type is introduced which provides an specific implementation
for bytes representing a WASM file owned by a SmartModule instance.

Resolves: #2700

@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch from 7d72265 to 31b3a93 Compare October 22, 2022 05:42
@EstebanBorai EstebanBorai marked this pull request as ready for review October 22, 2022 15:59
@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch 2 times, most recently from e405058 to c92bb75 Compare October 22, 2022 19:48
Copy link
Contributor

@sehz sehz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better. Couple of issues remain

crates/fluvio-protocol/src/core/wasm_bytes.rs Outdated Show resolved Hide resolved
crates/fluvio-protocol/src/core/wasm_bytes.rs Outdated Show resolved Hide resolved
@EstebanBorai EstebanBorai changed the title feat: introduce WasmBytes for SmartModuleSpec feat: introduce ByteBuf for SmartModuleSpec Oct 22, 2022
@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch 4 times, most recently from 2e6cbb4 to 7594c1d Compare October 23, 2022 04:18
@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch from 72c11e3 to 2199aec Compare October 24, 2022 14:39
@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch from 2199aec to 42ccaeb Compare October 25, 2022 21:17
@EstebanBorai EstebanBorai marked this pull request as draft October 25, 2022 21:17
@EstebanBorai EstebanBorai force-pushed the feat/wasmbytes-for-smartmodulespec branch 5 times, most recently from 44ab15b to 0e067f4 Compare October 27, 2022 20:00
@EstebanBorai
Copy link
Contributor Author

Implemented tests to make sure the output is the same as for encoding/decoding from Vec<u8>.

@morenol
Copy link
Contributor

morenol commented Nov 4, 2022

@sehz @morenol new implementation is looking very good!

test vecu8 encoding ... bench:      414738 ns/iter (+/- 29440)

test vecu8 decoding ... bench:      355882 ns/iter (+/- 11905)

test bytebuf encoding ... bench:        7909 ns/iter (+/- 235)

test bytebuf decoding ... bench:        7684 ns/iter (+/- 293)

These are the results benchmarking with Criterion as of b8f77a5

Very promising, I think that we should use ByteBuf in SmartModuleInput and maybe other places of the code where we use Vec<u8> and have Encode/Decode

@EstebanBorai
Copy link
Contributor Author

@sehz @morenol new implementation is looking very good!

test vecu8 encoding ... bench:      414738 ns/iter (+/- 29440)

test vecu8 decoding ... bench:      355882 ns/iter (+/- 11905)

test bytebuf encoding ... bench:        7909 ns/iter (+/- 235)

test bytebuf decoding ... bench:        7684 ns/iter (+/- 293)

These are the results benchmarking with Criterion as of b8f77a5

Very promising, I think that we should use ByteBuf in SmartModuleInput and maybe other places of the code where we use Vec

Totally agree!

@morenol
Copy link
Contributor

morenol commented Nov 4, 2022

I think that we could also grab Encoder implementation from this PR and add that to RecordData

impl Encoder for RecordData {

@EstebanBorai
Copy link
Contributor Author

that's 50x improvement. Can you benchmark with a bytes buffer with 100k, which is typical for SmartModule?

Im using a SmartModule WASM file for testing. Here is the file in question: https://github.com/EstebanBorai/fluvio/blob/feat/wasmbytes-for-smartmodulespec/crates/fluvio-protocol/fixtures/smartmodule.wasm.

The source for this file is actually a filter SmartModule example. Perhaps we could try with the RegExp example for a more "real-life" example?

@sehz
Copy link
Contributor

sehz commented Nov 4, 2022

That's good enough!

@sehz sehz modified the milestone: 0.10.1 Nov 4, 2022
Copy link
Contributor

@sehz sehz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress and very nice work. Just need couple of refinements

crates/fluvio-controlplane-metadata/Cargo.toml Outdated Show resolved Hide resolved
crates/fluvio-protocol/src/core/bytebuf.rs Show resolved Hide resolved
crates/fluvio-protocol/src/core/bytebuf.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@morenol morenol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement, it looks good to me just a couple of nits.

I see that CI test that checks crate version reports crates that need to be updated but it is not failing, maybe is it an issue with the exit code? CC @tjtelan

https://github.com/infinyon/fluvio/actions/runs/3395995671/jobs/5646561976

crates/fluvio-protocol/src/core/bytebuf.rs Outdated Show resolved Hide resolved
crates/fluvio-protocol/src/core/bytebuf.rs Outdated Show resolved Hide resolved
crates/fluvio-protocol/src/core/bytebuf.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@sehz sehz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few remaining nits

@@ -109,7 +110,7 @@ pub struct SmartModuleWasmSummary {
pub struct SmartModuleWasm {
pub format: SmartModuleWasmFormat,
#[cfg_attr(feature = "use_serde", serde(with = "base64"))]
pub payload: Vec<u8>,
pub payload: ByteBuf,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove pub signature, we don't need to expose it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fluvio-sc-schema uses the field:

wasm_length: self.wasm.payload.len() as u32,

I think we could expose it via method call (similar to the getter pattern)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could create a fn payload_len

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its good for this use case, but we also consume the payload directly for the SmartModuleInvocationWasm enum here:

error[E0616]: field `payload` of struct `SmartModuleWasm` is private
   --> crates/fluvio-spu/src/smartengine/context.rs:253:78
    |
253 |                 wasm: SmartModuleInvocationWasm::AdHoc(smartmodule.spec.wasm.payload.into()),

I think we could think of an API for these use case on a next PR? In order to encapsulate these fields, and
also provide some unit tests to these.

crates/fluvio-protocol/Cargo.toml Outdated Show resolved Hide resolved
crates/fluvio-controlplane-metadata/Cargo.toml Outdated Show resolved Hide resolved
crates/fluvio-protocol/src/core/bytebuf.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@sehz sehz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close. Last nit

crates/fluvio-sc-schema/Cargo.toml Show resolved Hide resolved
Copy link
Contributor

@sehz sehz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. Tremendous improvement. Ship it!

@EstebanBorai
Copy link
Contributor Author

bors r+

bors bot pushed a commit that referenced this pull request Nov 4, 2022
In order to have a more performant implementation on WASM bytes, a
dedicated type is introduced which provides an specific implementation
for bytes representing a WASM file owned by a `SmartModule` instance.

Resolves: #2700
@EstebanBorai
Copy link
Contributor Author

Nice work. Tremendous improvement. Ship it!

Thanks! And to everyone involved! :shipit:

@bors
Copy link

bors bot commented Nov 5, 2022

Pull request successfully merged into master.

Build succeeded:

  • Done

@bors bors bot changed the title feat: introduce ByteBuf for SmartModuleSpec [Merged by Bors] - feat: introduce ByteBuf for SmartModuleSpec Nov 5, 2022
@bors bors bot closed this Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

performance: Improve encoding/decoding of Vec<u8> for WASM
3 participants