Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/collections/linear_fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ pub struct LinearFifo<T, B: LinearFifoBuffer<T>> {
impl<T, const N: usize> LinearFifo<T, StaticBuffer<T, N>> {
/// `init` for `.Static`.
pub fn init() -> Self {
const {
assert!(
!mem::needs_drop::<T>(),
"LinearFifo does not drop its items; use VecDeque for types with drop glue"
)
};
Self {
buf: StaticBuffer([const { MaybeUninit::uninit() }; N]),
head: 0,
Expand All @@ -173,6 +179,12 @@ impl<T, const N: usize> LinearFifo<T, StaticBuffer<T, N>> {
impl<T> LinearFifo<T, DynamicBuffer<T>> {
/// `init` for `.Dynamic`.
pub fn init() -> Self {
const {
assert!(
!mem::needs_drop::<T>(),
"LinearFifo does not drop its items; use VecDeque for types with drop glue"
)
};
Self {
buf: DynamicBuffer(Box::new([])),
head: 0,
Expand All @@ -182,8 +194,11 @@ impl<T> LinearFifo<T, DynamicBuffer<T>> {
}
}

// `pub fn deinit` → Drop. Dynamic frees `buf` via `Box` drop; Static/Slice are
// no-ops. Field drop glue covers it; no explicit impl needed.
// `pub fn deinit` → Drop. Dynamic frees `buf` via `Box` drop; Static is a
// no-op. Items are never dropped: the ring is for POD/pointer payloads only,
// and the `!needs_drop::<T>()` const assert in each `init` enforces it, so
// e.g. `LinearFifo::<Box<u8>, DynamicBuffer<_>>::init()` fails to compile at
// monomorphization.
Comment thread
robobun marked this conversation as resolved.
Outdated

impl<T, B: LinearFifoBuffer<T>> LinearFifo<T, B> {
#[inline]
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/valkey_jsc/ValkeyCommand.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use bun_collections::linear_fifo::{DynamicBuffer, LinearFifo};
use bun_jsc::{self as jsc, JSGlobalObject, JSValue, JsResult};
use bun_valkey::valkey_protocol as protocol;

Expand Down Expand Up @@ -114,7 +113,7 @@ pub struct Entry {
// Inherent associated
// types are unstable on stable Rust, so expose as a sibling module alias instead.
pub mod entry {
pub(crate) type Queue = super::LinearFifo<super::Entry, super::DynamicBuffer<super::Entry>>;
pub(crate) type Queue = std::collections::VecDeque<super::Entry>;
}

impl Entry {
Expand Down Expand Up @@ -248,8 +247,7 @@ pub struct PromisePair {

// See `entry` note above.
pub mod promise_pair {
pub(crate) type Queue =
super::LinearFifo<super::PromisePair, super::DynamicBuffer<super::PromisePair>>;
pub(crate) type Queue = std::collections::VecDeque<super::PromisePair>;
}

impl PromisePair {
Expand Down
17 changes: 8 additions & 9 deletions src/runtime/valkey_jsc/js_valkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ impl JSValkeyClient {
protocol: uri,
username,
password,
in_flight: command::promise_pair::Queue::init(),
queue: command::entry::Queue::init(),
in_flight: command::promise_pair::Queue::new(),
queue: command::entry::Queue::new(),
status: valkey::Status::NeverConnected,
connection_strings,
socket: Socket::SocketTcp(uws::SocketTCP {
Expand Down Expand Up @@ -867,8 +867,8 @@ impl JSValkeyClient {
protocol: client.protocol,
username,
password,
in_flight: command::promise_pair::Queue::init(),
queue: command::entry::Queue::init(),
in_flight: command::promise_pair::Queue::new(),
queue: command::entry::Queue::new(),
status: valkey::Status::NeverConnected,
connection_strings: connection_strings_copy,
socket: Socket::SocketTcp(uws::SocketTCP {
Expand Down Expand Up @@ -1610,13 +1610,12 @@ impl JSValkeyClient {
memory_cost += client.read_buffer.byte_list.capacity() as usize;

// Add queue sizes
memory_cost += client.in_flight.readable_length()
* core::mem::size_of::<super::valkey_command::PromisePair>();
for command in client.queue.readable_slice(0) {
memory_cost +=
client.in_flight.len() * core::mem::size_of::<super::valkey_command::PromisePair>();
for command in client.queue.iter() {
memory_cost += command.serialized_data.len();
}
memory_cost +=
client.queue.readable_length() * core::mem::size_of::<super::valkey_command::Entry>();
memory_cost += client.queue.len() * core::mem::size_of::<super::valkey_command::Entry>();
memory_cost
}

Expand Down
Loading
Loading