{"record":{"id":"81f8b357afbf8523","repo":"zed-industries/zed","slug":"arena-chunk-size-of-is-too-small-to-allocate-bytes","errorCode":null,"errorMessage":"Arena chunk_size of {} is too small to allocate {} bytes","messagePattern":"Arena chunk_size of (.+?) is too small to allocate (.+?) bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui/src/arena.rs","lineNumber":209,"sourceCode":"        }\n    }\n\n    #[inline(never)]\n    fn allocate_next_chunk(&mut self, layout: alloc::Layout) -> *mut u8 {\n        self.current_chunk_index += 1;\n        if self.current_chunk_index >= self.chunks.len() {\n            self.chunks.push(Chunk::new(self.chunk_size));\n            assert_eq!(self.current_chunk_index, self.chunks.len() - 1);\n            log::trace!(\n                \"increased element arena capacity to {}kb\",\n                self.capacity() / 1024,\n            );\n        }\n        let current_chunk = &mut self.chunks[self.current_chunk_index];\n        if let Some(pointer) = current_chunk.allocate(layout) {\n            pointer.as_ptr()\n        } else {\n            panic!(\n                \"Arena chunk_size of {} is too small to allocate {} bytes\",\n                self.chunk_size,\n                layout.size()\n            );\n        }\n    }\n}\n\npub struct ArenaBox<T: ?Sized> {\n    ptr: *mut T,\n    valid: Rc<Cell<bool>>,\n}\n\nimpl<T: ?Sized> ArenaBox<T> {\n    #[inline(always)]\n    pub fn map<U: ?Sized>(mut self, f: impl FnOnce(&mut T) -> &mut U) -> ArenaBox<U> {\n        ArenaBox {\n            ptr: f(&mut self),","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/gpui/src/arena.rs#L191-L227","documentation":"GPUI's `Arena` is a bump allocator that allocates from fixed-size chunks. When a single allocation does not fit into a freshly created chunk, the arena panics, because it never splits one allocation across chunks — the `chunk_size` is simply too small for the requested layout. This is a configuration bug in the arena's constructor, not a recoverable condition.","triggerScenarios":"Calling `Arena::alloc` (via `allocate_next_chunk`) with a `Layout` whose size exceeds the arena's configured `chunk_size`, e.g. one very large string/buffer allocated through an arena whose chunk size is smaller.","commonSituations":"Constructing an arena with a hard-coded small chunk size and later feeding it unusually large payloads (big text buffers, large images); increases in data size after a chunk_size was tuned.","solutions":["Increase the arena's `chunk_size` so it is at least as large as the biggest single allocation you make (ideally several times larger).","Check the requested `layout.size()` at the failing call site and clamp/split oversized allocations before handing them to the arena.","Fall back to the heap (e.g. `Box`/`Vec`) for allocations that can exceed the chunk size."],"exampleFix":"// before\nlet arena = Arena::new(1024);\nlet p = arena.alloc(large_buffer); // panics: chunk too small\n// after\nlet arena = Arena::new(64 * 1024); // chunk_size >= max single allocation\nlet p = arena.alloc(large_buffer);","handlingStrategy":"validation","validationCode":"// check before allocating through the arena\nif layout.size() > arena_chunk_size {\n    return Err(anyhow!(\"allocation of {} bytes exceeds arena chunk_size {}\", layout.size(), arena_chunk_size));\n}\nlet ptr = arena.alloc(layout);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Size the arena chunk_size several times larger than your largest expected allocation.","Route oversized or variable-size payloads to the heap instead of the arena.","Add an assertion at construction time that chunk_size covers known maximum allocation sizes."],"tags":["arena","allocation","panic","memory","gpui"],"backgroundTag":"invalid-config-value","analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-09-19T19:09:50.599Z","contentChangedAt":"2026-09-19T19:09:50.599Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}