Skip to content

Memory usage #3499

@mazecrown

Description

@mazecrown

I'm running some tests using the standalone server on a macbook with a simple server to try and determine memory usage:

use spacetimedb::{ReducerContext, Table, reducer, table};

#[table(name = my_row, public, )]
pub struct MyRow {
    #[primary_key]
    #[auto_inc]
    pub id: u32,
    pub i: i32,
    // pub i2: i32,
}

const NUM_ROWS: i32 = 10_000_000;

#[reducer(init)]
pub fn init(ctx: &ReducerContext) {
    for i in 0..NUM_ROWS {
        ctx.db.my_row().insert(MyRow {
            id: 0,
            i: i,
            // i2: 2 * i,
        });
    }
    log::info!("inserted {NUM_ROWS} rows");
}

Toggling between NUM_ROWS = 1_000_000 and 10_000_000 and also toggling i2 on and off I see the following results using activity monitor to monitor spacetime-standalone process:

Num rows Num i32 in struct Memory used
1m 1 197.5MB
1m 2 237.3MB
10m 1 1.02GB
10m 2 1.53GB

I know its not the most scientific of tests but it looks like it results in an extra 40-50 bytes per row just to add another i32. Is this to be expected? Are there any rules of thumb about how to calculate expected memory usage?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions