Skip to content

Commit

Permalink
Merge pull request #124 from Totodore/feat-cow-namespace-and-rooms
Browse files Browse the repository at this point in the history
feat(socketio/ns): store ns path and rooms as `Cow<'static, str>`
  • Loading branch information
Totodore authored Oct 30, 2023
2 parents ab4d830 + 53db020 commit 8de2238
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 420 deletions.
14 changes: 2 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion socketioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ tower = { version = "0.4.13", default-features = false }
http = "0.2.9"
http-body = "0.4.5"
thiserror = "1.0.40"
itertools = "0.11.0"

# Extensions
dashmap = { version = "5.4.0", optional = true }
Expand Down
63 changes: 25 additions & 38 deletions socketioxide/benches/packet_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ use engineioxide::sid::Sid;
use socketioxide::{Packet, PacketData, ProtocolVersion};
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet connect on /", |b| {
let packet: String = Packet::connect(
black_box("/").to_string(),
black_box(Sid::ZERO),
ProtocolVersion::V5,
)
.try_into()
.unwrap();
let packet: String =
Packet::connect(black_box("/"), black_box(Sid::ZERO), ProtocolVersion::V5)
.try_into()
.unwrap();
b.iter(|| Packet::try_from(packet.clone()).unwrap())
});
c.bench_function("Decode packet connect on /custom_nsp", |b| {
let packet: String = Packet::connect(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(Sid::ZERO),
ProtocolVersion::V5,
)
Expand All @@ -27,21 +24,18 @@ fn criterion_benchmark(c: &mut Criterion) {
const BINARY: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
c.bench_function("Decode packet event on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box(data.clone()),
)
.try_into()
.unwrap();
let packet: String =
Packet::event(black_box("/"), black_box("event"), black_box(data.clone()))
.try_into()
.unwrap();
b.iter(|| Packet::try_from(packet.clone()).unwrap())
});

c.bench_function("Decode packet event on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::event(
black_box("custom_nsp").to_string(),
black_box("event").to_string(),
black_box("custom_nsp"),
black_box("event"),
black_box(data.clone()),
)
.try_into()
Expand All @@ -51,11 +45,8 @@ fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("Decode packet event with ack on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: Packet = Packet::event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box(data.clone()),
);
let packet: Packet =
Packet::event(black_box("/"), black_box("event"), black_box(data.clone()));
match packet.inner {
PacketData::Event(_, _, mut ack) => ack.insert(black_box(0)),
_ => panic!("Wrong packet type"),
Expand All @@ -67,8 +58,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet event with ack on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::event(
black_box("/custom_nsp").to_string(),
black_box("event").to_string(),
black_box("/custom_nsp"),
black_box("event"),
black_box(data.clone()),
);
match packet.inner {
Expand All @@ -82,20 +73,16 @@ fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("Decode packet ack on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::ack(
black_box("/").to_string(),
black_box(data.clone()),
black_box(0),
)
.try_into()
.unwrap();
let packet: String = Packet::ack(black_box("/"), black_box(data.clone()), black_box(0))
.try_into()
.unwrap();
b.iter(|| Packet::try_from(packet.clone()).unwrap())
});

c.bench_function("Decode packet ack on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::ack(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(data.clone()),
black_box(0),
)
Expand All @@ -107,8 +94,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet binary event (b64) on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::bin_event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box("/"),
black_box("event"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
)
Expand All @@ -120,8 +107,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet binary event (b64) on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::bin_event(
black_box("/custom_nsp").to_string(),
black_box("event").to_string(),
black_box("/custom_nsp"),
black_box("event"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
)
Expand All @@ -133,7 +120,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet binary ack (b64) on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::bin_ack(
black_box("/").to_string(),
black_box("/"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
black_box(0),
Expand All @@ -146,7 +133,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Decode packet binary ack (b64) on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet: String = Packet::bin_ack(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
black_box(0),
Expand Down
48 changes: 16 additions & 32 deletions socketioxide/benches/packet_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ use engineioxide::sid::Sid;
use socketioxide::{Packet, PacketData, ProtocolVersion};
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet connect on /", |b| {
let packet = Packet::connect(
black_box("/").to_string(),
black_box(Sid::ZERO),
ProtocolVersion::V5,
);
let packet = Packet::connect(black_box("/"), black_box(Sid::ZERO), ProtocolVersion::V5);
b.iter(|| {
let _: String = packet.clone().try_into().unwrap();
})
});
c.bench_function("Encode packet connect on /custom_nsp", |b| {
let packet = Packet::connect(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(Sid::ZERO),
ProtocolVersion::V5,
);
Expand All @@ -27,11 +23,7 @@ fn criterion_benchmark(c: &mut Criterion) {
const BINARY: [u8; 10] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
c.bench_function("Encode packet event on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box(data.clone()),
);
let packet = Packet::event(black_box("/"), black_box("event"), black_box(data.clone()));
b.iter(|| {
let _: String = packet.clone().try_into().unwrap();
})
Expand All @@ -40,8 +32,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet event on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::event(
black_box("custom_nsp").to_string(),
black_box("event").to_string(),
black_box("custom_nsp"),
black_box("event"),
black_box(data.clone()),
);
b.iter(|| {
Expand All @@ -51,11 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("Encode packet event with ack on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box(data.clone()),
);
let packet = Packet::event(black_box("/"), black_box("event"), black_box(data.clone()));
match packet.inner {
PacketData::Event(_, _, mut ack) => ack.insert(black_box(0)),
_ => panic!("Wrong packet type"),
Expand All @@ -68,8 +56,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet event with ack on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::event(
black_box("/custom_nsp").to_string(),
black_box("event").to_string(),
black_box("/custom_nsp"),
black_box("event"),
black_box(data.clone()),
);
match packet.inner {
Expand All @@ -83,11 +71,7 @@ fn criterion_benchmark(c: &mut Criterion) {

c.bench_function("Encode packet ack on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::ack(
black_box("/").to_string(),
black_box(data.clone()),
black_box(0),
);
let packet = Packet::ack(black_box("/"), black_box(data.clone()), black_box(0));
b.iter(|| {
let _: String = packet.clone().try_into().unwrap();
})
Expand All @@ -96,7 +80,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet ack on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::ack(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(data.clone()),
black_box(0),
);
Expand All @@ -108,8 +92,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet binary event (b64) on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::bin_event(
black_box("/").to_string(),
black_box("event").to_string(),
black_box("/"),
black_box("event"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
);
Expand All @@ -121,8 +105,8 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet binary event (b64) on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::bin_event(
black_box("/custom_nsp").to_string(),
black_box("event").to_string(),
black_box("/custom_nsp"),
black_box("event"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
);
Expand All @@ -134,7 +118,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet binary ack (b64) on /", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::bin_ack(
black_box("/").to_string(),
black_box("/"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
black_box(0),
Expand All @@ -147,7 +131,7 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("Encode packet binary ack (b64) on /custom_nsp", |b| {
let data = serde_json::to_value(DATA).unwrap();
let packet = Packet::bin_ack(
black_box("/custom_nsp").to_string(),
black_box("/custom_nsp"),
black_box(data.clone()),
black_box(vec![BINARY.to_vec().clone()]),
black_box(0),
Expand Down
Loading

0 comments on commit 8de2238

Please sign in to comment.