rust-lang / rust-lang/rust-analyzer

Slow MBE expansion with `async-std`

Open
#11,363 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-macro A-parser A-perf C-bug S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

use async_std::io;
use async_std::net::{TcpListener, TcpStream};
use async_std::prelude::*;
use async_std::task;

async fn process(stream: TcpStream) -> io::Result<()> {
    println!("Accepted from: {}", stream.peer_addr()?);

    let mut reader = stream.clone();
    let mut writer = stream;
    io::copy(&mut reader, &mut writer).await?;

    Ok(())
}

fn main() -> io::Result<()> {
    task::block_on(async {
        let listener = TcpListener::bind("127.0.0.1:8080").await?;
        println!("Listening on {}", listener.local_addr()?);

        let mut incoming = listener.incoming();

        while let Some(stream) = incoming.next().await {
            let stream = stream?;
            task::spawn(async {
                process(stream).await.unwrap();
            });
        }
        Ok(())
    })
}

(cargo add async-std)

17606ms - import_map_query
    17605ms - collect_import_map
        16270ms - collect_trait_assoc_items
                1ms - crate_def_map:wait (3080 calls)
              622ms - file_item_tree_query (1539 calls)
             5273ms - macro_expand (1539 calls)
             7458ms - parse_macro_expansion (2987 calls)
            0   - PerNs::filter_visibility (244 calls)
            0   - PerNs::iter_items (200 calls)
         1060ms - collect_trait_assoc_items (27 calls)
          275ms - crate_def_map:wait (1 calls)
        0   - fst_path (292 calls)

38442ms - handle_hover
    11300ms - classify_name_ref @ next
        11300ms - Semantics::analyze_impl
            11300ms - infer:wait @ main
                0   - SourceBinder::to_module_def (1 calls)
                0   - crate_def_map:wait (1 calls)
        0   - crate_def_map:wait (21 calls)
        0   - descend_into_macros (1 calls)
     5908ms - parse_macro_expansion (1532 calls)
    21234ms - ???

28820ms - handle_hover
        0   - classify_name_ref (1 calls)
        0   - crate_def_map:wait (24 calls)
        0   - descend_into_macros (1 calls)
    17672ms - parse_macro_expansion (4016 calls)
    11148ms - ???

27826ms - handle_hover
        0   - classify_name_ref (1 calls)
        0   - crate_def_map:wait (21 calls)
        0   - descend_into_macros (1 calls)
    17895ms - parse_macro_expansion (4337 calls)
     9930ms - ???

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the slowdown with the async-std example and profiling data in the issue. Start by investigating import_map_query, collect_trait_assoc_items, macro_expand, parse_macro_expansion, and handle_hover. Done means the reported expansion and hover latency is reduced and the relevant profiling measurements improve.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.