Skip to content

Large futures in producer send path (clippy::large_futures warnings, excessive state held across await) #347

@ChrisWrenDev

Description

@ChrisWrenDev

When using the Pulsar producer APIs (e.g. Producer::send_non_blocking), downstream crates often trigger Clippy’s large_futures lint and sometimes have to manually wrap the returned futures in Box::pin(...).

The root cause is that methods like send_compress and send_inner are defined as async fns, but they only build and return another future. Because they’re written this way, the compiler generates state machines that temporarily hold large values—such as Vec<u8> payloads, batch buffers, and compression branches—across suspension points. This makes the resulting futures “wide,” and any caller that awaits producer.send_non_blocking(...) inherits those large temporaries in its own state machine.

As a result, even small downstream async functions can appear “too large” to Clippy, producing large_futures warnings. This pushes consumers of the library to heap-allocate (via Box::pin) just to reduce future sizes. That workaround adds boilerplate, masks the underlying issue, and may negatively affect compile times—or, in extreme cases, stack usage when futures are deeply nested.

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