diff options
-rw-r--r-- | ext/http/http_next.rs | 5 | ||||
-rw-r--r-- | ext/http/slab.rs | 14 |
2 files changed, 18 insertions, 1 deletions
diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index e95839005..5635fbd4b 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -12,6 +12,7 @@ use crate::response_body::ResponseBytesInner; use crate::response_body::V8StreamHttpResponseBody; use crate::slab::slab_drop; use crate::slab::slab_get; +use crate::slab::slab_init; use crate::slab::slab_insert; use crate::slab::SlabId; use crate::websocket_upgrade::WebSocketUpgrade; @@ -836,6 +837,8 @@ pub fn op_http_serve<HTTP>( where HTTP: HttpPropertyExtractor, { + slab_init(); + let listener = HTTP::get_listener_for_rid(&mut state.borrow_mut(), listener_rid)?; @@ -886,6 +889,8 @@ pub fn op_http_serve_on<HTTP>( where HTTP: HttpPropertyExtractor, { + slab_init(); + let connection = HTTP::get_connection_for_rid(&mut state.borrow_mut(), connection_rid)?; diff --git a/ext/http/slab.rs b/ext/http/slab.rs index 9f7c1f3e9..dbe1a6635 100644 --- a/ext/http/slab.rs +++ b/ext/http/slab.rs @@ -32,7 +32,7 @@ pub struct HttpSlabRecord { } thread_local! { - static SLAB: RefCell<Slab<HttpSlabRecord>> = RefCell::new(Slab::with_capacity(1024)); + static SLAB: RefCell<Slab<HttpSlabRecord>> = const { RefCell::new(Slab::new()) }; } macro_rules! http_trace { @@ -56,6 +56,18 @@ pub struct SlabEntry( RefMut<'static, Slab<HttpSlabRecord>>, ); +const SLAB_CAPACITY: usize = 1024; + +pub fn slab_init() { + SLAB.with(|slab: &RefCell<Slab<HttpSlabRecord>>| { + // Note that there might already be an active HTTP server, so this may just + // end up adding room for an additional SLAB_CAPACITY items. All HTTP servers + // on a single thread share the same slab. + let mut slab = slab.borrow_mut(); + slab.reserve(SLAB_CAPACITY); + }) +} + pub fn slab_get(index: SlabId) -> SlabEntry { http_trace!(index, "slab_get"); let mut lock: RefMut<'static, Slab<HttpSlabRecord>> = SLAB.with(|x| { |