Skip to content

Commit

Permalink
Remove the expand option on the describe route (#1755)
Browse files Browse the repository at this point in the history
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
  • Loading branch information
bfops and bfops authored Sep 30, 2024
1 parent 3865183 commit dc4457b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 60 deletions.
13 changes: 2 additions & 11 deletions crates/cli/src/subcommands/describe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::common_args;
use crate::config::Config;
use crate::util::{add_auth_header_opt, database_address, get_auth_header_only};
use clap::{Arg, ArgAction::SetTrue, ArgMatches};
use clap::{Arg, ArgMatches};

pub fn cli() -> clap::Command {
clap::Command::new("describe")
Expand All @@ -21,8 +21,6 @@ pub fn cli() -> clap::Command {
.requires("entity_type")
.help("The name of the entity to describe"),
)
.arg(Arg::new("brief").long("brief").short('b').action(SetTrue)
.help("If this flag is present, a brief description shall be returned"))
.arg(
common_args::identity()
.conflicts_with("anon_identity")
Expand All @@ -41,7 +39,6 @@ pub fn cli() -> clap::Command {

pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> {
let database = args.get_one::<String>("database").unwrap();
let expand = !args.get_flag("brief");
let entity_name = args.get_one::<String>("entity_name");
let entity_type = args.get_one::<String>("entity_type");
let server = args.get_one::<String>("server").map(|s| s.as_ref());
Expand All @@ -64,13 +61,7 @@ pub async fn exec(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::E
let auth_header = get_auth_header_only(&mut config, anon_identity, identity, server).await?;
let builder = add_auth_header_opt(builder, &auth_header);

let descr = builder
.query(&[("expand", expand)])
.send()
.await?
.error_for_status()?
.text()
.await?;
let descr = builder.send().await?.error_for_status()?.text().await?;
println!("{}", descr);

Ok(())
Expand Down
72 changes: 23 additions & 49 deletions crates/client-api/src/routes/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'a> EntityDef<'a> {
}
}

fn entity_description_json(description: WithTypespace<EntityDef>, expand: bool) -> Option<Value> {
fn entity_description_json(description: WithTypespace<EntityDef>) -> Option<Value> {
let typ = description.ty().described_entity_ty().as_str();
let len = match description.ty() {
EntityDef::Table(t) => description
Expand All @@ -233,32 +233,25 @@ fn entity_description_json(description: WithTypespace<EntityDef>, expand: bool)
.len(),
EntityDef::Reducer(r) => r.params.elements.len(),
};
if expand {
// TODO(noa): make this less hacky; needs coordination w/ spacetime-web
let schema = match description.ty() {
EntityDef::Table(table) => {
json!(description
.with(&table.product_type_ref)
.resolve_refs()
.ok()?
.as_product()?)
}
EntityDef::Reducer(r) => json!({
"name": &r.name[..],
"elements": r.params.elements,
}),
};
Some(json!({
"type": typ,
"arity": len,
"schema": schema
}))
} else {
Some(json!({
"type": typ,
"arity": len,
}))
}
// TODO(noa): make this less hacky; needs coordination w/ spacetime-web
let schema = match description.ty() {
EntityDef::Table(table) => {
json!(description
.with(&table.product_type_ref)
.resolve_refs()
.ok()?
.as_product()?)
}
EntityDef::Reducer(r) => json!({
"name": &r.name[..],
"elements": r.params.elements,
}),
};
Some(json!({
"type": typ,
"arity": len,
"schema": schema
}))
}

#[derive(Deserialize)]
Expand All @@ -268,19 +261,13 @@ pub struct DescribeParams {
entity: String,
}

#[derive(Deserialize)]
pub struct DescribeQueryParams {
expand: Option<bool>,
}

pub async fn describe<S>(
State(worker_ctx): State<S>,
Path(DescribeParams {
name_or_address,
entity_type,
entity,
}): Path<DescribeParams>,
Query(DescribeQueryParams { expand }): Query<DescribeQueryParams>,
Extension(auth): Extension<SpacetimeAuth>,
) -> axum::response::Result<impl IntoResponse>
where
Expand Down Expand Up @@ -311,8 +298,7 @@ where
.ok_or_else(|| (StatusCode::NOT_FOUND, format!("{entity_type} {entity:?} not found")))?;
let description = WithTypespace::new(module.info().module_def.typespace(), &description);

let expand = expand.unwrap_or(true);
let response_json = json!({ entity: entity_description_json(description, expand) });
let response_json = json!({ entity: entity_description_json(description) });

Ok((
StatusCode::OK,
Expand Down Expand Up @@ -343,26 +329,18 @@ pub struct CatalogParams {
}
#[derive(Deserialize)]
pub struct CatalogQueryParams {
expand: Option<bool>,
#[serde(default)]
module_def: bool,
}
pub async fn catalog<S>(
State(worker_ctx): State<S>,
Path(CatalogParams { name_or_address }): Path<CatalogParams>,
Query(CatalogQueryParams { expand, module_def }): Query<CatalogQueryParams>,
Query(CatalogQueryParams { module_def }): Query<CatalogQueryParams>,
Extension(auth): Extension<SpacetimeAuth>,
) -> axum::response::Result<impl IntoResponse>
where
S: ControlStateDelegate + NodeDelegate,
{
if module_def && expand.is_some() {
return Err((
StatusCode::BAD_REQUEST,
"expand and module_def cannot both be specified",
)
.into());
}
let address = name_or_address.resolve(&worker_ctx).await?.into();
let database = worker_ctx_find_database(&worker_ctx, &address)
.await?
Expand All @@ -381,15 +359,11 @@ where
let raw = RawModuleDefV9::from(module.info().module_def.clone());
serde_json::to_value(SerializeWrapper::from_ref(&raw)).map_err(log_and_500)?
} else {
let expand = expand.unwrap_or(false);
let response_catalog: HashMap<_, _> = get_catalog(&module)
.map(|entity| {
(
entity.name().to_string().into_boxed_str(),
entity_description_json(
WithTypespace::new(module.info().module_def.typespace(), &entity),
expand,
),
entity_description_json(WithTypespace::new(module.info().module_def.typespace(), &entity)),
)
})
.collect();
Expand Down

2 comments on commit dc4457b

@github-actions
Copy link

@github-actions github-actions bot commented on dc4457b Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Criterion benchmark report

YOU SHOULD PROBABLY IGNORE THESE RESULTS.

Criterion is a wall time based benchmarking system that is extremely noisy when run on CI. We collect these results for longitudinal analysis, but they are not reliable for comparing individual PRs.

Go look at the callgrind report instead.

empty

db on disk new latency old latency new throughput old throughput
sqlite 💿 421.9±2.10ns 422.7±2.01ns - -
sqlite 🧠 416.3±2.30ns 413.6±1.59ns - -
stdb_raw 💿 621.3±3.60ns 624.6±0.84ns - -
stdb_raw 🧠 621.2±1.66ns 624.5±1.61ns - -

insert_1

db on disk schema indices preload new latency old latency new throughput old throughput

insert_bulk

db on disk schema indices preload count new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str btree_each_column 2048 256 590.4±0.96µs 582.9±0.68µs 1693 tx/sec 1715 tx/sec
sqlite 💿 u32_u64_str unique_0 2048 256 154.8±0.52µs 150.1±0.72µs 6.3 Ktx/sec 6.5 Ktx/sec
sqlite 💿 u32_u64_u64 btree_each_column 2048 256 470.7±0.82µs 466.4±0.40µs 2.1 Ktx/sec 2.1 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 2048 256 137.3±0.54µs 136.4±0.57µs 7.1 Ktx/sec 7.2 Ktx/sec
sqlite 🧠 u32_u64_str btree_each_column 2048 256 453.6±0.45µs 445.0±0.36µs 2.2 Ktx/sec 2.2 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 2048 256 125.3±0.79µs 123.7±0.59µs 7.8 Ktx/sec 7.9 Ktx/sec
sqlite 🧠 u32_u64_u64 btree_each_column 2048 256 371.0±0.16µs 364.8±0.59µs 2.6 Ktx/sec 2.7 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 2048 256 108.3±0.32µs 105.9±0.36µs 9.0 Ktx/sec 9.2 Ktx/sec
stdb_raw 💿 u32_u64_str btree_each_column 2048 256 588.3±19.29µs 581.1±24.23µs 1699 tx/sec 1720 tx/sec
stdb_raw 💿 u32_u64_str unique_0 2048 256 507.5±23.67µs 494.7±28.37µs 1970 tx/sec 2021 tx/sec
stdb_raw 💿 u32_u64_u64 btree_each_column 2048 256 355.6±20.20µs 386.2±5.91µs 2.7 Ktx/sec 2.5 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 2048 256 309.6±9.73µs 351.5±5.15µs 3.2 Ktx/sec 2.8 Ktx/sec
stdb_raw 🧠 u32_u64_str btree_each_column 2048 256 310.7±1.42µs 307.1±0.24µs 3.1 Ktx/sec 3.2 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 2048 256 242.3±0.19µs 240.6±0.46µs 4.0 Ktx/sec 4.1 Ktx/sec
stdb_raw 🧠 u32_u64_u64 btree_each_column 2048 256 252.0±0.12µs 251.2±0.13µs 3.9 Ktx/sec 3.9 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 2048 256 223.3±0.45µs 221.2±0.27µs 4.4 Ktx/sec 4.4 Ktx/sec

iterate

db on disk schema indices new latency old latency new throughput old throughput
sqlite 💿 u32_u64_str unique_0 24.2±0.12µs 22.3±0.19µs 40.4 Ktx/sec 43.7 Ktx/sec
sqlite 💿 u32_u64_u64 unique_0 22.6±0.18µs 21.0±0.14µs 43.2 Ktx/sec 46.4 Ktx/sec
sqlite 🧠 u32_u64_str unique_0 21.5±0.19µs 19.7±0.17µs 45.4 Ktx/sec 49.5 Ktx/sec
sqlite 🧠 u32_u64_u64 unique_0 19.8±0.14µs 18.4±0.09µs 49.3 Ktx/sec 53.0 Ktx/sec
stdb_raw 💿 u32_u64_str unique_0 4.8±0.00µs 4.7±0.00µs 204.9 Ktx/sec 207.3 Ktx/sec
stdb_raw 💿 u32_u64_u64 unique_0 4.6±0.00µs 4.6±0.00µs 210.8 Ktx/sec 211.5 Ktx/sec
stdb_raw 🧠 u32_u64_str unique_0 4.8±0.00µs 4.7±0.00µs 205.1 Ktx/sec 206.9 Ktx/sec
stdb_raw 🧠 u32_u64_u64 unique_0 4.6±0.00µs 4.6±0.00µs 210.7 Ktx/sec 211.5 Ktx/sec

find_unique

db on disk key type preload new latency old latency new throughput old throughput

filter

db on disk key type index strategy load count new latency old latency new throughput old throughput
sqlite 💿 string index 2048 256 69.3±0.29µs 69.7±0.13µs 14.1 Ktx/sec 14.0 Ktx/sec
sqlite 💿 u64 index 2048 256 66.5±0.16µs 65.9±0.14µs 14.7 Ktx/sec 14.8 Ktx/sec
sqlite 🧠 string index 2048 256 65.3±0.22µs 65.1±0.15µs 15.0 Ktx/sec 15.0 Ktx/sec
sqlite 🧠 u64 index 2048 256 60.9±0.10µs 60.7±0.11µs 16.0 Ktx/sec 16.1 Ktx/sec
stdb_raw 💿 string index 2048 256 4.9±0.00µs 4.8±0.00µs 199.1 Ktx/sec 202.4 Ktx/sec
stdb_raw 💿 u64 index 2048 256 4.8±0.00µs 4.7±0.00µs 202.6 Ktx/sec 205.8 Ktx/sec
stdb_raw 🧠 string index 2048 256 4.9±0.01µs 4.8±0.00µs 198.8 Ktx/sec 202.5 Ktx/sec
stdb_raw 🧠 u64 index 2048 256 4.8±0.00µs 4.7±0.00µs 202.6 Ktx/sec 205.8 Ktx/sec

serialize

schema format count new latency old latency new throughput old throughput
u32_u64_str bflatn_to_bsatn_fast_path 100 3.3±0.01µs 3.5±0.04µs 29.2 Mtx/sec 27.5 Mtx/sec
u32_u64_str bflatn_to_bsatn_slow_path 100 3.9±0.05µs 3.5±0.00µs 24.7 Mtx/sec 27.6 Mtx/sec
u32_u64_str bsatn 100 2.3±0.02µs 2.4±0.06µs 41.6 Mtx/sec 39.2 Mtx/sec
u32_u64_str bsatn 100 40.5±0.07ns 40.4±0.12ns 2.3 Gtx/sec 2.3 Gtx/sec
u32_u64_str json 100 4.9±0.04µs 4.6±0.03µs 19.6 Mtx/sec 20.6 Mtx/sec
u32_u64_str json 100 6.7±0.02µs 6.9±0.02µs 14.2 Mtx/sec 13.9 Mtx/sec
u32_u64_str product_value 100 1017.2±0.70ns 1018.8±0.64ns 93.8 Mtx/sec 93.6 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_fast_path 100 1138.8±7.11ns 1128.8±4.47ns 83.7 Mtx/sec 84.5 Mtx/sec
u32_u64_u64 bflatn_to_bsatn_slow_path 100 2.8±0.01µs 2.8±0.00µs 34.4 Mtx/sec 34.0 Mtx/sec
u32_u64_u64 bsatn 100 1544.2±11.08ns 1746.5±32.84ns 61.8 Mtx/sec 54.6 Mtx/sec
u32_u64_u64 bsatn 100 39.4±0.04ns 28.8±0.05ns 2.4 Gtx/sec 3.2 Gtx/sec
u32_u64_u64 json 100 3.4±0.04µs 3.0±0.00µs 27.8 Mtx/sec 31.6 Mtx/sec
u32_u64_u64 json 100 4.7±0.02µs 4.4±0.12µs 20.1 Mtx/sec 21.5 Mtx/sec
u32_u64_u64 product_value 100 1011.9±1.18ns 1013.3±5.76ns 94.2 Mtx/sec 94.1 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_fast_path 100 901.6±14.00ns 897.5±5.52ns 105.8 Mtx/sec 106.3 Mtx/sec
u64_u64_u32 bflatn_to_bsatn_slow_path 100 2.8±0.00µs 2.8±0.00µs 34.3 Mtx/sec 33.8 Mtx/sec
u64_u64_u32 bsatn 100 1550.9±9.68ns 1835.3±47.30ns 61.5 Mtx/sec 52.0 Mtx/sec
u64_u64_u32 bsatn 100 751.4±0.20ns 751.6±0.71ns 126.9 Mtx/sec 126.9 Mtx/sec
u64_u64_u32 json 100 3.5±0.04µs 3.1±0.09µs 27.2 Mtx/sec 30.4 Mtx/sec
u64_u64_u32 json 100 4.9±0.08µs 4.5±0.01µs 19.6 Mtx/sec 21.3 Mtx/sec
u64_u64_u32 product_value 100 1016.8±0.97ns 1015.1±0.39ns 93.8 Mtx/sec 94.0 Mtx/sec

stdb_module_large_arguments

arg size new latency old latency new throughput old throughput
64KiB 115.2±9.44µs 110.1±7.66µs - -

stdb_module_print_bulk

line count new latency old latency new throughput old throughput
1 57.5±5.40µs 59.8±5.34µs - -
100 600.2±7.97µs 605.6±14.14µs - -
1000 5.0±0.63ms 4.9±0.86ms - -

remaining

name new latency old latency new throughput old throughput
special/db_game/circles/load=10 287.6±2.11µs 292.4±2.99µs - -
special/db_game/circles/load=100 287.4±2.92µs 289.2±3.27µs - -
special/db_game/ia_loop/load=10 0.0±0.00ns 0.0±0.00ns - -
special/db_game/ia_loop/load=100 0.0±0.00ns 0.0±0.00ns - -
sqlite/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 56.5±0.23µs 53.6±0.09µs 17.3 Ktx/sec 18.2 Ktx/sec
sqlite/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 48.9±0.21µs 46.0±0.03µs 20.0 Ktx/sec 21.2 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 42.3±0.21µs 38.4±0.12µs 23.1 Ktx/sec 25.4 Ktx/sec
sqlite/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 37.1±0.59µs 35.1±0.09µs 26.3 Ktx/sec 27.8 Ktx/sec
stdb_module/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 1228.8±23.94µs 1257.6±16.15µs 813 tx/sec 795 tx/sec
stdb_module/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 992.9±11.61µs 984.8±7.56µs 1007 tx/sec 1015 tx/sec
stdb_raw/💿/update_bulk/u32_u64_str/unique_0/load=2048/count=256 640.2±19.11µs 633.2±39.91µs 1562 tx/sec 1579 tx/sec
stdb_raw/💿/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 455.1±23.66µs 490.3±8.03µs 2.1 Ktx/sec 2039 tx/sec
stdb_raw/🧠/update_bulk/u32_u64_str/unique_0/load=2048/count=256 372.0±0.52µs 374.1±0.67µs 2.6 Ktx/sec 2.6 Ktx/sec
stdb_raw/🧠/update_bulk/u32_u64_u64/unique_0/load=2048/count=256 338.5±0.22µs 338.6±0.24µs 2.9 Ktx/sec 2.9 Ktx/sec

@github-actions
Copy link

@github-actions github-actions bot commented on dc4457b Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark results Error when comparing benchmarks:

Caused by:

Please sign in to comment.