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

Refactor re_sdk::Session #1528

Merged
merged 37 commits into from
Mar 9, 2023
Merged

Refactor re_sdk::Session #1528

merged 37 commits into from
Mar 9, 2023

Conversation

emilk
Copy link
Member

@emilk emilk commented Mar 7, 2023

Backstory

Session was originally designed for internal use by the Python API. It was then reused as the main interface for the Rust API. However, the needs of the Python API and the Rust API are quite different:

  • In Rust we support multiple Sessions, while in Python we currently have one global session
  • In Rust i makes sense to use the builder pattern to set up the Sesssion once, while in Python we have methods to change the recording id etc as the session is alive
  • The Session needs to be ergonomic and user-facing for our Rust API, while in Python is an implementation detail
  • From Python there is only one user of the session (the Python bindings), but in Rust one could be many users (many threads)

What this PR does

This PR does two major things:

  • Creates a PythonSession for internal use in rerun_py. It is a slightly simplified version of the old Session.
  • Session is now vastly simpler, with only a few methods. It can be constructed with a SessionBuilder.

This separation allow us to more easily evolve the Python and Rust APIs independently.

The Rust Session is now associated with one LogSink for the duration of its lifetime. To connect to something else you create a new Session.

Session is also Clone, Send and Sync so it can easily be used from multiple threads.

Why tho?

I want to be able to easily hook up the tracing log stream to send its log events to Rerun, and for that I need to get an Arc<dyn LogSink>, which lead me down this rabbit hole. Each Session needs to start by sending off a BeginRecordingMsg, and its only after that is sent that one should be able to share a Session, hence this refactor to a builder-pattern.

Checklist

@emilk emilk added the 🦀 Rust API Rust logging API label Mar 7, 2023
@@ -0,0 +1,243 @@
use std::net::SocketAddr;
Copy link
Member Author

Choose a reason for hiding this comment

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

The following file is the old session.rs, with a few small refactorings

@emilk emilk marked this pull request as ready for review March 7, 2023 14:59
@emilk emilk marked this pull request as draft March 7, 2023 15:56
@emilk emilk marked this pull request as ready for review March 7, 2023 16:06
crates/rerun/src/clap.rs Outdated Show resolved Hide resolved
@jleibs jleibs self-assigned this Mar 9, 2023
Copy link
Member

@jleibs jleibs left a comment

Choose a reason for hiding this comment

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

😅 that was a long one!

Couple of small issues/questions but overall looks like a great improvement.

examples/rust/minimal/src/main.rs Outdated Show resolved Hide resolved
examples/rust/raw_mesh/src/main.rs Outdated Show resolved Hide resolved
@@ -25,7 +24,7 @@ py_folders := "examples rerun_py scripts"
py-dev-env:
#!/usr/bin/env bash
echo "Setting up Python virtual environment in venv"
# set -euxo pipefail
set -euxo pipefail
Copy link
Member

Choose a reason for hiding this comment

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

A bit curious why this was commented out before?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm suspecting it was a mistake

@@ -41,9 +41,6 @@ def lint_line(line: str) -> Optional[str]:
if "todo!()" in line:
return 'todo!() should be written as todo!("$details")'

if "dbg!(" in line and not line.startswith("//"):
Copy link
Member

Choose a reason for hiding this comment

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

Any particular reason we're removing this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is (better) checked by clippy in clippy.toml

emilk and others added 4 commits March 9, 2023 10:27
Co-authored-by: Jeremy Leibs <jeremy@rerun.io>
Co-authored-by: Jeremy Leibs <jeremy@rerun.io>
@emilk emilk merged commit 93edfca into main Mar 9, 2023
@emilk emilk deleted the emilk/refactor-session branch March 9, 2023 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦀 Rust API Rust logging API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants