Skip to content

Task spawning in a loop is too slow (not caching stacks right?) #15363

Closed
@pcwalton

Description

@pcwalton

This program is 10x slower than the equivalent in Go:

extern crate green;

use std::task::TaskBuilder;
use green::{SchedPool, PoolConfig, GreenTaskBuilder};
use native::NativeTaskBuilder;

fn main() {
    let mut pool = SchedPool::new(PoolConfig::new());
    for _ in range(0u, 100000) {
        let future = TaskBuilder::new().green(&mut pool).stack_size(65536).try_future(proc() {});
        drop(future.unwrap());
    }
    pool.shutdown();
}

Profiling indicates lots of stack allocation. Interestingly enough, bumping up RUST_MAX_CACHED_STACKS makes things much slower. So I believe stacks are never getting cached. Perhaps the stack isn't being returned by the time the future is unwrapped?

cc @alexcrichton

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-concurrencyArea: ConcurrencyA-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflowsI-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions