Skip to main content

BufferSizeHint

Enum BufferSizeHint 

Source
pub enum BufferSizeHint {
    Small,
    Medium,
    Large,
    Huge,
}
Expand description

Buffer size hints for different workload profiles.

These size classes provide pre-configured buffer sizes optimized for common use cases, from embedded systems to high-throughput data processing.

§Size Classes

  • Small (8KB): Embedded systems, small config files, memory-constrained environments
  • Medium (64KB): Default for general use, good balance of performance and memory
  • Large (256KB): Large files, high-throughput scenarios, server workloads
  • Huge (1MB): Multi-GB files, maximum performance, minimal syscall overhead

§Performance Characteristics

Larger buffers reduce system call overhead but use more memory. The optimal size depends on:

  • File size (larger files benefit from larger buffers)
  • Available memory (constrained systems need smaller buffers)
  • I/O characteristics (fast storage benefits more from large buffers)
  • Access pattern (sequential vs. random)

§Examples

§Automatic Selection

use hedl_stream::{StreamingParserConfig, BufferSizeHint};

let config = StreamingParserConfig::default()
    .with_buffer_hint(BufferSizeHint::Large);

assert_eq!(config.buffer_size, 256 * 1024);

§Custom Configuration

use hedl_stream::{StreamingParserConfig, BufferSizeHint};

// Small embedded device
let embedded_config = StreamingParserConfig::default()
    .with_buffer_hint(BufferSizeHint::Small);

// High-throughput server
let server_config = StreamingParserConfig::default()
    .with_buffer_hint(BufferSizeHint::Huge);

Variants§

§

Small

8KB buffer - for embedded systems and small files.

Use when:

  • Parsing config files (<1MB)
  • Running on embedded systems
  • Memory is very limited (<10MB available)
  • Processing many small files concurrently

Trade-offs:

  • Minimal memory footprint
  • More system calls for large files
  • Lower throughput on fast storage
§

Medium

64KB buffer - default for general use.

Use when:

  • General-purpose parsing
  • No specific performance requirements
  • Mixed file sizes
  • Standard development environments

Trade-offs:

  • Good balance of memory and performance
  • Suitable for most workloads
  • May not be optimal for extremes
§

Large

256KB buffer - for large files and high throughput.

Use when:

  • Parsing large files (>100MB)
  • High-throughput ETL pipelines
  • Fast storage (NVMe SSD)
  • Server environments with available memory

Trade-offs:

  • Reduced syscall overhead
  • Better throughput on large files
  • Higher memory usage per parser
§

Huge

1MB buffer - maximum performance for huge files.

Use when:

  • Parsing multi-GB files
  • Maximum throughput required
  • Abundant memory available
  • Single-threaded processing

Trade-offs:

  • Minimal syscall overhead
  • Maximum throughput
  • Significant memory per parser (limits concurrency)

Implementations§

Source§

impl BufferSizeHint

Source

pub const fn size(self) -> usize

Get the buffer size in bytes for this hint.

§Examples
use hedl_stream::BufferSizeHint;

assert_eq!(BufferSizeHint::Small.size(), 8 * 1024);
assert_eq!(BufferSizeHint::Medium.size(), 64 * 1024);
assert_eq!(BufferSizeHint::Large.size(), 256 * 1024);
assert_eq!(BufferSizeHint::Huge.size(), 1024 * 1024);
Source

pub fn for_file_size(size_bytes: u64) -> Self

Get a buffer size hint based on file size.

Automatically selects an appropriate buffer size based on the total size of the file being parsed.

§Heuristics
  • Files <1MB: Small (8KB)
  • Files 1-100MB: Medium (64KB)
  • Files 100MB-1GB: Large (256KB)
  • Files >1GB: Huge (1MB)
§Examples
use hedl_stream::BufferSizeHint;

let hint = BufferSizeHint::for_file_size(500 * 1024); // 500KB
assert_eq!(hint, BufferSizeHint::Small);

let hint = BufferSizeHint::for_file_size(50 * 1024 * 1024); // 50MB
assert_eq!(hint, BufferSizeHint::Medium);

let hint = BufferSizeHint::for_file_size(500 * 1024 * 1024); // 500MB
assert_eq!(hint, BufferSizeHint::Large);

let hint = BufferSizeHint::for_file_size(2 * 1024 * 1024 * 1024); // 2GB
assert_eq!(hint, BufferSizeHint::Huge);
Source

pub fn for_memory_budget( available_memory: usize, concurrent_parsers: usize, ) -> Self

Get a buffer size hint for memory-constrained environments.

Recommends a buffer size that won’t exceed the given memory budget when running concurrent_parsers simultaneously.

§Examples
use hedl_stream::BufferSizeHint;

// 10MB available, running 10 parsers concurrently
let hint = BufferSizeHint::for_memory_budget(10 * 1024 * 1024, 10);
// Should suggest Small (8KB) since 10 * 64KB = 640KB is reasonable

Trait Implementations§

Source§

impl Clone for BufferSizeHint

Source§

fn clone(&self) -> BufferSizeHint

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BufferSizeHint

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BufferSizeHint

Source§

fn default() -> BufferSizeHint

Returns the “default value” for a type. Read more
Source§

impl Hash for BufferSizeHint

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BufferSizeHint

Source§

fn eq(&self, other: &BufferSizeHint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BufferSizeHint

Source§

impl Eq for BufferSizeHint

Source§

impl StructuralPartialEq for BufferSizeHint

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.