Skip to content

perf: Cut encrypted outbound batch time by up to 73% - #473

Draft
kdcokenny wants to merge 10 commits into
Steel-Foundation:masterfrom
kdcokenny:kdcokenny/optimize-encrypted-outbound-transport
Draft

perf: Cut encrypted outbound batch time by up to 73%#473
kdcokenny wants to merge 10 commits into
Steel-Foundation:masterfrom
kdcokenny:kdcokenny/optimize-encrypted-outbound-transport

Conversation

@kdcokenny

@kdcokenny kdcokenny commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Type of change

  • Refactor / code cleanup
  • Performance improvement

Description

Removes bottlenecks from encrypted play-state output without changing the packet bytes or order a Vanilla client receives.

  • Encrypts reusable byte groups instead of passing ciphertext to Tokio one byte at a time.
  • Gives the play sender sole ownership of its writer, removing the per-packet lock.
  • Sends bundles and chunk batches as one ordered group, so unrelated packets cannot appear inside them.
  • Flushes after 32 packets or 256 KiB, then gives other connections a turn.
  • Keeps queued packet order during graceful disconnects while retaining one bounded close deadline for stalled clients.
  • Drops an incomplete encrypted stream instead of reusing invalid packet or cipher state.

Single packets still go out immediately, and batching never waits for future packets.

Release-mode encrypted loopback A/B results used fixed Linux CPU affinity, 20 samples, three-second measurements, and both benchmark orders:

Workload Old behavior Optimized Result
8 small packets 19.48 µs 5.17 µs 73.5% faster
868-packet synthetic burst 4.51 ms 2.82 ms 37.5% faster
9-chunk group 1.72 ms 1.69 ms No regression (~2% faster)
Small-packet encryption 1.46 ms 1.12 ms 23.3% faster
Mixed-size encryption 3.80 ms 2.94 ms 22.5% faster

In two paired 256-sample runs with another connection busy, batching reduced both median and 95th-percentile control-packet delay. The old path's tail varied widely, so this PR does not claim a fixed latency percentage.

How this was tested

Parity tests cover continuous CFB8 output, partial writes, pending flushes, absolute close deadlines, FIFO disconnect ordering, batch contiguity, writer handoff, and login encryption transitions.

All Steel Core, Steel Login, and Steel Protocol tests passed. The change was also validated with a Vanilla Minecraft 26.2 client on the latest Windows release.

Screenshots / logs

Not applicable.

Checklist

  • Code builds w/o errors or warnings
  • Self-reviewed the diff
  • Docs updated (not applicable)
  • No leftover debug code / comments

@kdcokenny kdcokenny changed the title perf: Optimize encrypted outbound play transport perf: Speed up encrypted outbound play transport Aug 24, 2026
@kdcokenny kdcokenny changed the title perf: Speed up encrypted outbound play transport perf: Cut encrypted outbound batch time by up to 73% Aug 24, 2026
@kdcokenny
kdcokenny marked this pull request as ready for review August 24, 2026 18:36
Comment thread steel-core/src/player/connection/java.rs Outdated
@github-actions

Copy link
Copy Markdown

This pull request has conflicts with the base branch "master". Please resolve those so we can test out your changes.

@github-actions

Copy link
Copy Markdown

Conflicts have been resolved! 🎉

@kdcokenny
kdcokenny marked this pull request as draft August 26, 2026 01:11
@kdcokenny
kdcokenny marked this pull request as ready for review August 26, 2026 17:52
@MarshY2k

Copy link
Copy Markdown
Contributor

macro_refactor.txt

@kdcokenny
kdcokenny requested review from Joniii11 and banocean August 28, 2026 03:03

@Joniii11 Joniii11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

Comment on lines +71 to 77
fn send_encoded_batch(&self, packets: Vec<EncodedPacket>) {
self.packets.lock().extend(packets);
}

fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>) {
self.packets.lock().extend(packets);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what are the difference ?

Comment on lines +141 to 147
fn send_encoded_batch(&self, packets: Vec<EncodedPacket>) {
(**self).send_encoded_batch(packets);
}

fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>) {
(**self).send_encoded_bundle(packets);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look duplicate

Comment on lines +771 to 777
fn send_encoded_batch(&self, _packets: Vec<EncodedPacket>) {
self.record_if_armed();
}

fn send_encoded_bundle(&self, _packets: Vec<EncodedPacket>) {
self.record_if_armed();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look duplicate

Comment on lines +187 to 193
fn send_encoded_batch(&self, packets: Vec<EncodedPacket>) {
self.sent_packets.lock().extend(packets);
}

fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>) {
self.sent_packets.lock().extend(packets);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look duplicate

Comment on lines +88 to 94
fn send_encoded_batch(&self, packets: Vec<EncodedPacket>) {
self.sent_packets.lock().extend(packets);
}

fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>) {
self.sent_packets.lock().extend(packets);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look duplicate

Comment on lines +127 to 133
fn send_encoded_batch(&self, packets: Vec<EncodedPacket>) {
self.packets.lock().extend(packets);
}

fn send_encoded_bundle(&self, packets: Vec<EncodedPacket>) {
self.packets.lock().extend(packets);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

look duplicate

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's no the same as steel-core/benches/outbound_transport.rs ?

@coco875

coco875 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

hmm look like that your batch overlap with bundle that was made before and #545 also try something similar ?

@kdcokenny
kdcokenny marked this pull request as draft September 2, 2026 18:52
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

This pull request has conflicts with the base branch "master". Please resolve those so we can test out your changes.

@JunkyDeveloper

Copy link
Copy Markdown
Contributor

will you continue this PR and finish it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants