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

flatbuffers #1064

Merged
merged 112 commits into from Nov 8, 2023
Merged

flatbuffers #1064

merged 112 commits into from Nov 8, 2023

Conversation

jmillan
Copy link
Member

@jmillan jmillan commented Apr 17, 2023

WIP to remove JSON in favour of flatbuffers for as the worker communication format.

  • JSON parsing is CPU intensive.
  • JSON is not type safe.
  • flatbuffers does not parse the buffer. Reading the message takes 0ms.
  • flatbuffers is type safe since code (C++, Typescript, Rust, etc) is autogenerated out of the schema definitions.

Extras that come along with this changes:

  • There is now a single Channel for worker communication.
    • Previously there were 2 (Channel and PayloadChannel)
  • Each message sent Node->Worker requires a single write() call to Channel.
    • Previously 2 calls per message were needed for Channel and 4 for PayloadChannel.
  • Each message sent Worker->Node previously executed two extra calls to memcpy that are not executed now.

TODO: flatbuffers related

  • Try to scope notifications per instance so we don't rely on a global flatbuffers notification event enum but an enum per class (producer, consumer, transport, etc.): FBS: WIP, scope notifications #1162 (non blocker)
  • Do not use heap on flatbuffers generation (non blocker)
  • Do not use head on flatbuffers processing (non blocker)

TODO: flatbuffers unrealed. Changes made in flatbuffer branch, not present in v3

@jmillan jmillan mentioned this pull request Apr 17, 2023
2 tasks
@ibc
Copy link
Member

ibc commented May 17, 2023

@jmillan this branch uses NPM flatbuffers 23.3.3 and there is 23.5.9 already. CHANGELOG here: https://github.com/google/flatbuffers/blob/master/CHANGELOG.md

I'm merging v3 into flatbuffers and will later upgrade this dep.

@ibc
Copy link
Member

ibc commented May 17, 2023

@jmillan this branch uses NPM flatbuffers 23.3.3 and there is 23.5.9 already. CHANGELOG here: https://github.com/google/flatbuffers/blob/master/CHANGELOG.md

I'm merging v3 into flatbuffers and will later upgrade this dep.

Done and pushed.

ibc added 6 commits May 18, 2023 12:41
# Conflicts:
#	worker/src/RTC/RtpStream.cpp
# Conflicts:
#	.github/workflows/mediasoup-node.yaml
#	.gitignore
#	CHANGELOG.md
#	npm-scripts.js
#	worker/src/lib.cpp
# Conflicts:
#	CHANGELOG.md
#	npm-scripts.mjs
#	package.json
# Conflicts:
#	npm-scripts.mjs
@ibc
Copy link
Member

ibc commented Jun 1, 2023

Questions. Sometimes I see this:

if (flatbuffers::IsFieldPresent(options->listenInfo(), FBS::Transport::ListenInfo::VT_ANNOUNCEDIP))

and sometimes I see this (which is way nicer):

if (body->port().has_value())
{
    port = body->port().value();
}

I'd love if the latter could be used everywhere, no idea if possible.

@ibc
Copy link
Member

ibc commented Jun 1, 2023

I may be crazy but make lint doesn't detect wrong changes in PlainTransport.cpp although it does in other XxxxTransport.cpp classes...

@ibc
Copy link
Member

ibc commented Jun 1, 2023

@jmillan, in the TODO items above:

flatbuffers (TS) should throw TypeError instead of Error when there is a missing required field. PR done.

It's been merged. Not sure if there is a new release of flatbuffers for Node, but if so we should change some code, right?

@jmillan
Copy link
Member Author

jmillan commented Jun 6, 2023

flatbuffers (TS) should throw TypeError instead of Error when there is a missing required field. google/flatbuffers#7910.

It's been merged. Not sure if there is a new release of flatbuffers for Node, but if so we should change some code, right?

Removed explicit TypeError exceptions.

# Conflicts:
#	CHANGELOG.md
…iled files (#1198)

- Instead of writing into all transpiled JS files in `node/lib/`, read `package.json` just once in launch time and read "version" from it.
- I'm not happy with this, not sure if better than before. But clearly we are gonna remove this useless `mediasoup.version` public getter in v4.
@ibc
Copy link
Member

ibc commented Oct 27, 2023

@jmillan @nazar-pc, the most important missing piece here is:

  • Build rust/src/fbs.rs at build time (planus) (blocker)

So I'd like to discuss about this.

Problem

Currently, as soon as we change/add/delete any file in worker/fbs folder, we must perform these steps manually in rust directory:

  1. We need to have planus-cli installed (cargo install planus-cli).
  2. planus rust -o src/fbs.rs ../worker/fbs/*.fbs
  3. Then revert some of the changes at the top of rust/src/fbs.rs file to make sure it re-exports things the same way and suppresses clippy warnings.

Questions

  1. Does an external contributor have to install planus-cli manually? Or are we gonna add planus-cli in [dev-dependencies] in rust/Cargo.toml?
  • Off-topic: How is the cargo command to install dev deps?
  1. So assuming we have planus-cli, how are we gonna automatize steps 2 and 3 above? Is this gonna be a new task in main Makefile? Or can we have a custom cargo run planus command (does such a thing exist?) and use cargo-cli as a lib?

@nazar-pc
Copy link
Collaborator

nazar-pc commented Oct 27, 2023

  1. Neither, we'll use Planus as a library and compile files programmatically from build.rs instead
  2. They are installed automatically when you run tests, etc. It is not the same notion as Node.js. For equivalent stuff to Node.js there are [build-dependencies], those are dependencies needed for build.rs
  3. We will programmatically compile files as part of build.rs and emit cargo:rerun-if-changed to instruct Cargo to re-run build.rs only if any of the files change (should also include C++ files)

@ibc
Copy link
Member

ibc commented Oct 27, 2023

we'll use Planus as a library and compile files programmatically from build.rs instead

  • So we have to run cargo build or cargo test to update fbs.rs, right?
  • So we have to add ugly code in build.rs to "revert some of the changes at the top of rust/src/fbs.rs file to make sure it re-exports things the same way and suppresses clippy warnings", right?

@nazar-pc
Copy link
Collaborator

nazar-pc commented Oct 27, 2023

So we have to run cargo build or cargo test to update fbs.rs, right?

Neither and both. We will no longer ship fbs.rs, it will be compiled automatically when you run cargo test or use mediasoup as a dependency, but as mentioned before, only if it wasn't compiled already or corresponding files have changed.

So we have to add ugly code in build.rs to "revert some of the changes at the top of rust/src/fbs.rs file to make sure it re-exports things the same way and suppresses clippy warnings", right?

I believe we do not, we can just suppress warnings on the whole module. Basically we will have #[allow(clippy::whatever)] mod fbs {included_code_here} or something like that in lib.rs, no manual search/replace will be necessary in build.rs.

ibc and others added 8 commits October 27, 2023 14:04
FBS: Simplify Data[Consumer|Producer] send messages

For some reason we were not sending everything as binary in this branch.
Update Cargo.lock which was missing.
FBS: Remove unneeded message type member

It's not needed since the body contained in the message is aleady typed.
@ibc
Copy link
Member

ibc commented Oct 31, 2023

I'm writing all missing docs in versatica/mediasoup-website#50

.gitignore Outdated Show resolved Hide resolved
Do not put there anything that it's not related to the project (such as files autogenerated by project tasks/scripts).
Everything else (`.vscode`, `.idea`, `.DS_Store`, etc) can be individually added to our local `.git/info/exclude` file).
@ibc
Copy link
Member

ibc commented Oct 31, 2023

@jmillan I'm marking this PR as ready.

@ibc ibc marked this pull request as ready for review October 31, 2023 16:02
ibc and others added 8 commits October 31, 2023 17:10
* FBS: Node, Fix RtpParameters

Always pass encodings, header extensions and rtcp.
It makes it complain for every log or assert macro.
- Do not call `cleanWorkerArtifacts()` in `flatcNode()`. No reason for that plus it is bypassing the `MEDIASOUP_LOCAL_DEV` env purpose.
- Use more readable object arguments.
Do not process handshake if there is no remote fingerprint.
@jmillan jmillan merged commit a7d46d8 into v3 Nov 8, 2023
34 of 36 checks passed
@jmillan jmillan deleted the flatbuffers branch November 8, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants