Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I define very complex routes with axum web framework, the compilation time increases a lot #88322

Closed
paulzhang5511 opened this issue Aug 25, 2021 · 5 comments
Labels
C-bug Category: This is a bug.

Comments

@paulzhang5511
Copy link

paulzhang5511 commented Aug 25, 2021

When I define very complex routes with axum web framework, the compilation time increases a lot. This should be rustc's problem.

Example: https://github.com/paulzhang5511/axum-compile-slow

let app = Router::new()
        .nest(
            "/",
            axum::service::get(ServeDir::new("./publish").append_index_html_on_directories(true))
                .handle_error(|error: std::io::Error| {
                    Ok::<_, std::convert::Infallible>((
                        StatusCode::INTERNAL_SERVER_ERROR,
                        format!("Unhandled internal error: {}", error),
                    ))
                }),
        )
        .nest(
            "/upload",
            axum::service::get(ServeDir::new("./upload").append_index_html_on_directories(false))
                .handle_error(|error: std::io::Error| {
                    tracing::debug!("{:?}", error);
                    Ok::<_, std::convert::Infallible>((
                        StatusCode::INTERNAL_SERVER_ERROR,
                        "read file error".to_string(),
                    ))
                }),
        )
        .nest(
            "/api",
            Router::new()
                .route("/pay/pay_params", post(handle))
                .route("/pay/transfer_info", post(handle))
                .route("/upload/image", post(handle))
                .nest(
                    "/user",
                    Router::new()
                        .route("/list", get(handle))
                        .route("/create", post(handle))
                        .route("/login", post(handle))
                        .route("/info", get(handle))
                        .route("/update_password", get(handle))
                        .route("/money", get(handle)),
                )
                .nest(
                    "/order",
                    Router::new()
                        .route("/create", post(handle))
                        .route("/all", get(handle))
                        .route("/list", get(handle)),
                )
                .nest(
                    "/product",
                    Router::new()
                        .route("/list", get(handle))
                        .route("/home", get(handle))
                        .route("/create", post(handle))
                        .route("/update/:id", post(handle))
                        .route("/delete", post(handle))
                        .route("/detail", get(handle))
                        .route("/earnings/create", post(handle))
                        .route("/earnings/delete", post(handle))
                        .route("/earnings/find", get(handle))
                        .boxed(),
                )
                .layer(AsyncFilterLayer::new(map_request))
                .layer(AndThenLayer::new(map_response))
                .handle_error(|error: BoxError| {
                    if error.is::<tower::timeout::error::Elapsed>() {
                        Ok::<_, Infallible>((
                            StatusCode::REQUEST_TIMEOUT,
                            "request took too long".to_string(),
                        ))
                    } else {
                        tracing::debug!("{:?}", error);
                        Ok::<_, Infallible>((
                            StatusCode::INTERNAL_SERVER_ERROR,
                            "Unhandled internal error".to_string(),
                        ))
                    }
                }),
        )
        .layer(MapResponseLayer::new(map_404))
        .layer(
            ServiceBuilder::new()
                .timeout(Duration::from_secs(15))
                .layer(TraceLayer::new_for_http())
                .layer(AddExtensionLayer::new(pool))
                .into_inner(),
        );

Meta

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1
@paulzhang5511 paulzhang5511 added the C-bug Category: This is a bug. label Aug 25, 2021
@kate-shine
Copy link

Related to #87924 (which was closed, because a workaround in Axum was introduced - workaround that solved the issue only partially it seems.)

Related Axum issue: tokio-rs/axum#200

@EliseZeroTwo
Copy link
Contributor

I am having similar issues while using Axum. Running the compiler with -Z time-passes shows the compiler getting caught in the following:

time: 137.000; rss:  418MB -> 7332MB (+6914MB)	item_bodies_checking
time: 137.446; rss:  280MB -> 7332MB (+7052MB)	type_check_crate

and your provided example shows similar results:

time:  86.958; rss:  242MB -> 1522MB (+1280MB)	item_bodies_checking
time:  87.017; rss:  177MB -> 1522MB (+1345MB)	type_check_crate

@Ten0
Copy link

Ten0 commented Oct 18, 2021

We're having a similar issue with a rather large crate constructing a lot of diesel queries (~500):

time:  46.403; rss: 1574MB -> 2899MB (+1325MB)	item_bodies_checking
time:  51.842; rss: 1274MB -> 2899MB (+1625MB)	type_check_crate

Since these passes are also present in cargo check, this makes getting feedback on a minor code change very slow, dramatically increasing development time.

@Ten0
Copy link

Ten0 commented Jan 12, 2022

Is this resolved by #90996 (comment) or something else?

@Ten0
Copy link

Ten0 commented Jan 31, 2022

Can we know what closes this? (Because we are still hitting our similar issue)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants