Skip to content

Double tokio::spawn introduces unnecessary task scheduling overhead #34

@coderabbitai

Description

@coderabbitai

Problem

The current implementation uses double tokio::spawn calls, creating unnecessary task churn:
listener.accept()spawn(process_stream) → inside process_stream another spawn(app.handle_connection)

Affected Locations

  • Lines 341-342 in src/server.rs
  • Lines 373-376 in src/server.rs

Current Code

tokio::spawn(async move {
    app.handle_connection(stream).await;
});

Suggested Improvement

Unless the inner spawn isolates crash-safety or blocking work, call app.handle_connection directly:

app.handle_connection(stream).await;

Benefits

  • Reduces task scheduling overhead
  • Simplifies the execution flow
  • Eliminates one unnecessary context switch

Context

This is a performance optimization that reduces the complexity of the async task execution without affecting functionality.

References

Reported by: @leynos

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions