Skip to content

Option<T> parameters in poise::command function cause exponential compile times #376

@calebberhow

Description

@calebberhow

Description

Given a command like with many Option<T> parameters, the poise::command proc-macro leads to exponentially increasing compilation times for commands with more parameters. This affect does not occur for non-optional parameters.

Expected behavior

Functions with the poise::command proc macro should compile in a reasonable amount of time, or there should be an explicit upper limit on the number of parameters allowed.

Current Behavior

Below are some data from my testing

Test Case cargo check time
12 String params 0.22s
8 Option<bool> params 0.22s
9 Option<bool> params 6.4s
10 Option<bool> params 27.51s
8 Option<String> params 0.22s
9 Option<String> params 25.5s
10 Option<String> params 2m 57s

Steps to reproduce

Write a function like the following and witness cargo check take a very long time to complete.

See minimum reproducible example repo for full project.

#[poise::command(slash_command, prefix_command)]
pub async fn test(
    _ctx: poise::Context<'_, (), Box<dyn std::error::Error + Send + Sync>>,
    _param1: Option<String>,
    _param2: Option<String>,
    _param3: Option<String>,
    _param4: Option<String>,
    _param5: Option<String>,
    _param6: Option<String>,
    _param7: Option<String>,
    _param8: Option<String>,
    // Warning: long compile times, may stall out rust extension
    _param9: Option<String>,
    // Warning: extremely long compile times, may stall out rust extension
    // _param10: Option<String>,
    // Warning: doesn't compile on my machine, as it runs out of memory (20+ GB RAM usage).
    // _param11: Option<String>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    Ok(())
}

Testing environment

Operating system: Windows 11
CPU architecture: x86-64
Cargo version: cargo 1.92.0 (344c4567c 2025-10-21)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions