Skip to content

Commit

Permalink
box warp routes
Browse files Browse the repository at this point in the history
box warp routes to avoid super heavy types.
Performance impact should be okay, since these heavy types
are not cache friendly.

This reduces type complexity significantly, but some really long type chains remain.

I've identified two, but they may be more
1. Boxed or chains
2. Response type chains

We can replace the boxed or chains with a Vec, since they all contain the same
box type now. Such a type doesn't seem to exist in warp yet.

`cargo install --path .`
Compile time before
4m49s
Compile time now
4m14s

Tool to list heavy functions:
`
CARGO_PROFILE_RELEASE_LTO=fat cargo llvm-lines --release --bin quickwit > llvm_lines
`
Size down from 32MB to 22MB

addresses #5539
  • Loading branch information
PSeitz committed Nov 5, 2024
1 parent ee362fc commit 2e18bb1
Show file tree
Hide file tree
Showing 15 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/cluster_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn cluster_handler(
.then(get_cluster)
.and(extract_format_from_qs())
.map(into_rest_api_response)
.recover(recover_fn)
.recover(recover_fn).boxed()
}

#[utoipa::path(
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/delete_task_api/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn delete_task_api_handlers(
) -> impl Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
get_delete_tasks_handler(metastore.clone())
.or(post_delete_tasks_handler(metastore.clone()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

pub fn get_delete_tasks_handler(
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/developer_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(crate) fn developer_api_routes(
warp::path!("api" / "developer" / ..)
.and(
debug_handler(cluster.clone())
.or(log_level_handler(env_filter_reload_fn.clone()))
.or(log_level_handler(env_filter_reload_fn.clone()).boxed())
.or(pprof_handlers()),
)
.recover(recover_fn)
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/elasticsearch_api/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn es_compat_index_bulk_handler(
)
.and(extract_format_from_qs())
.map(make_elastic_api_response)
.recover(recover_fn)
.recover(recover_fn).boxed()
}

async fn elastic_ingest_bulk(
Expand Down
6 changes: 3 additions & 3 deletions quickwit/quickwit-serve/src/elasticsearch_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,22 @@ pub fn elastic_api_handlers(
.or(es_compat_bulk_handler(
ingest_service.clone(),
ingest_router.clone(),
))
)).boxed()
.or(es_compat_index_bulk_handler(ingest_service, ingest_router))
.or(es_compat_index_search_handler(search_service.clone()))
.or(es_compat_index_count_handler(search_service.clone()))
.or(es_compat_scroll_handler(search_service.clone()))
.or(es_compat_index_multi_search_handler(search_service.clone()))
.or(es_compat_index_field_capabilities_handler(
search_service.clone(),
))
)).boxed()
.or(es_compat_index_stats_handler(metastore.clone()))
.or(es_compat_delete_index_handler(index_service))
.or(es_compat_stats_handler(metastore.clone()))
.or(es_compat_index_cat_indices_handler(metastore.clone()))
.or(es_compat_cat_indices_handler(metastore.clone()))
.or(es_compat_resolve_index_handler(metastore.clone()))
.recover(recover_fn)
.recover(recover_fn).boxed()
// Register newly created handlers here.
}

Expand Down
22 changes: 11 additions & 11 deletions quickwit/quickwit-serve/src/elasticsearch_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn es_compat_cluster_info_handler(
}
}))
},
)
).boxed()
}

/// GET or POST _elastic/_search
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn es_compat_delete_index_handler(
elastic_delete_index_filter()
.and(with_arg(index_service))
.then(es_compat_delete_index)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.map(|result| make_elastic_api_response(result, BodyFormat::default())).boxed()
}

/// GET _elastic/_stats
Expand All @@ -145,7 +145,7 @@ pub fn es_compat_stats_handler(
.and(with_arg(metastore_service))
.then(es_compat_stats)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET _elastic/{index}/_stats
Expand All @@ -156,7 +156,7 @@ pub fn es_compat_index_stats_handler(
.and(with_arg(metastore_service))
.then(es_compat_index_stats)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET _elastic/_cat/indices
Expand All @@ -167,7 +167,7 @@ pub fn es_compat_cat_indices_handler(
.and(with_arg(metastore_service))
.then(es_compat_cat_indices)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET _elastic/_cat/indices/{index}
Expand All @@ -178,7 +178,7 @@ pub fn es_compat_index_cat_indices_handler(
.and(with_arg(metastore_service))
.then(es_compat_index_cat_indices)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET _elastic/_resolve/index/{index}
Expand All @@ -188,7 +188,7 @@ pub fn es_compat_resolve_index_handler(
elastic_resolve_index_filter()
.and(with_arg(metastore_service))
.then(es_compat_resolve_index)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.map(|result| make_elastic_api_response(result, BodyFormat::default())).boxed()
}

/// GET or POST _elastic/{index}/_search
Expand All @@ -199,7 +199,7 @@ pub fn es_compat_index_search_handler(
.and(with_arg(search_service))
.then(es_compat_index_search)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET or POST _elastic/{index}/_count
Expand All @@ -210,7 +210,7 @@ pub fn es_compat_index_count_handler(
.and(with_arg(search_service))
.then(es_compat_index_count)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// POST _elastic/_msearch
Expand All @@ -227,7 +227,7 @@ pub fn es_compat_index_multi_search_handler(
};
RestApiResponse::new(&result, status_code, BodyFormat::default())
})
.recover(recover_fn)
.recover(recover_fn).boxed()
}

/// GET or POST _elastic/_search/scroll
Expand All @@ -238,7 +238,7 @@ pub fn es_compat_scroll_handler(
.and(with_arg(search_service))
.then(es_scroll)
.map(|result| make_elastic_api_response(result, BodyFormat::default()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

fn build_request_for_es_api(
Expand Down
36 changes: 18 additions & 18 deletions quickwit/quickwit-serve/src/index_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,28 @@ pub fn index_management_handlers(
node_config: Arc<NodeConfig>,
) -> impl Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
// Indexes handlers.
get_index_metadata_handler(index_service.metastore())
.or(list_indexes_metadata_handler(index_service.metastore()))
.or(create_index_handler(index_service.clone(), node_config))
.or(update_index_handler(index_service.metastore()))
.or(clear_index_handler(index_service.clone()))
.or(delete_index_handler(index_service.clone()))
get_index_metadata_handler(index_service.metastore()).boxed()
.or(list_indexes_metadata_handler(index_service.metastore()).boxed())
.or(create_index_handler(index_service.clone(), node_config).boxed())
.or(update_index_handler(index_service.metastore()).boxed())
.or(clear_index_handler(index_service.clone()).boxed())
.or(delete_index_handler(index_service.clone()).boxed())
// Splits handlers
.or(list_splits_handler(index_service.metastore()))
.or(describe_index_handler(index_service.metastore()))
.or(mark_splits_for_deletion_handler(index_service.metastore()))
.or(list_splits_handler(index_service.metastore()).boxed())
.or(describe_index_handler(index_service.metastore()).boxed())
.or(mark_splits_for_deletion_handler(index_service.metastore()).boxed())
// Sources handlers.
.or(reset_source_checkpoint_handler(index_service.metastore()))
.or(toggle_source_handler(index_service.metastore()))
.or(create_source_handler(index_service.clone()))
.or(get_source_handler(index_service.metastore()))
.or(delete_source_handler(index_service.metastore()))
.or(get_source_shards_handler(index_service.metastore()))
.or(reset_source_checkpoint_handler(index_service.metastore()).boxed())
.or(toggle_source_handler(index_service.metastore()).boxed())
.or(create_source_handler(index_service.clone()).boxed())
.or(get_source_handler(index_service.metastore()).boxed())
.or(delete_source_handler(index_service.metastore()).boxed())
.or(get_source_shards_handler(index_service.metastore()).boxed())
// Tokenizer handlers.
.or(analyze_request_handler())
.or(analyze_request_handler().boxed())
// Parse query into query AST handler.
.or(parse_query_request_handler())
.recover(recover_fn)
.or(parse_query_request_handler().boxed())
.recover(recover_fn).boxed()
}

fn json_body<T: DeserializeOwned + Send>(
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/indexing_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ pub fn indexing_get_handler(
.then(indexing_endpoint)
.and(extract_format_from_qs())
.map(into_rest_api_response)
.recover(recover_fn)
.recover(recover_fn).boxed()
}
8 changes: 4 additions & 4 deletions quickwit/quickwit-serve/src/ingest_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub(crate) fn ingest_api_handlers(
) -> impl Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
ingest_handler(ingest_service.clone(), config.clone())
.or(tail_handler(ingest_service))
.or(ingest_v2_handler(ingest_router, config))
.or(ingest_v2_handler(ingest_router, config)).boxed()
}

fn ingest_filter(
Expand All @@ -95,7 +95,7 @@ fn ingest_handler(
ingest_filter(config)
.and(with_arg(ingest_service))
.then(ingest)
.map(|result| into_rest_api_response(result, BodyFormat::default()))
.map(|result| into_rest_api_response(result, BodyFormat::default())).boxed()
}

fn ingest_v2_filter(
Expand All @@ -120,7 +120,7 @@ fn ingest_v2_handler(
.and(with_arg(ingest_router))
.then(ingest_v2)
.and(with_arg(BodyFormat::default()))
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}

async fn ingest_v2(
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn tail_handler(
.and(with_arg(ingest_service))
.then(tail_endpoint)
.and(extract_format_from_qs())
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}

fn tail_filter() -> impl Filter<Extract = (String,), Error = Rejection> + Clone {
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/jaeger_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) fn jaeger_api_handlers(
))
.or(jaeger_traces_search_handler(jaeger_service_opt.clone()))
.or(jaeger_traces_handler(jaeger_service_opt.clone()))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

fn jaeger_api_path_filter() -> impl Filter<Extract = (Vec<String>,), Error = Rejection> + Clone {
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-serve/src/node_info_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn node_info_handler(
) -> impl Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
node_version_handler(build_info, runtime_info)
.or(node_config_handler(config))
.recover(recover_fn)
.recover(recover_fn).boxed()
}

#[utoipa::path(get, tag = "Node Info", path = "/version")]
Expand Down
10 changes: 5 additions & 5 deletions quickwit/quickwit-serve/src/otlp_api/rest_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn otlp_ingest_api_handlers(
otlp_default_logs_handler(otlp_logs_service.clone())
.or(otlp_default_traces_handler(otlp_traces_service.clone()).recover(recover_fn))
.or(otlp_logs_handler(otlp_logs_service).recover(recover_fn))
.or(otlp_ingest_traces_handler(otlp_traces_service).recover(recover_fn))
.or(otlp_ingest_traces_handler(otlp_traces_service).recover(recover_fn)).boxed()
}

/// Open Telemetry REST/Protobuf logs ingest endpoint.
Expand Down Expand Up @@ -90,7 +90,7 @@ pub(crate) fn otlp_default_logs_handler(
},
)
.and(with_arg(BodyFormat::default()))
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}
/// Open Telemetry REST/Protobuf logs ingest endpoint.
#[utoipa::path(
Expand All @@ -115,7 +115,7 @@ pub(crate) fn otlp_logs_handler(
.and(get_body_bytes())
.then(otlp_ingest_logs)
.and(with_arg(BodyFormat::default()))
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}

/// Open Telemetry REST/Protobuf traces ingest endpoint.
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) fn otlp_default_traces_handler(
},
)
.and(with_arg(BodyFormat::default()))
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}
/// Open Telemetry REST/Protobuf traces ingest endpoint.
#[utoipa::path(
Expand All @@ -175,7 +175,7 @@ pub(crate) fn otlp_ingest_traces_handler(
.and(get_body_bytes())
.then(otlp_ingest_traces)
.and(with_arg(BodyFormat::default()))
.map(into_rest_api_response)
.map(into_rest_api_response).boxed()
}

#[derive(Debug, Clone, thiserror::Error, Serialize)]
Expand Down
Loading

0 comments on commit 2e18bb1

Please sign in to comment.