Skip to content

Abysmal performance of terminated() in rust-analyzer #1870

@dtdesign

Description

@dtdesign

I’m in the process of writing a parser that goes through log lines and have the need of discarding small segments. I have used (or abused) terminated() for this since it allows me to combine it in one step instead of matching the strings with tag() and discarding it by mapping the result.

One thing I have quickly noticed that chaining multiple terminated() within one tuple massively slows down the IDE suggestions up to a point where rust-analyzer is just pinning a CPU core for eternity. I have set up a tiny reproducer that only uses two terminated() calls which for me is sufficient to cause a delay in the neighborhood of 3-4 seconds.

https://github.com/dtdesign/nom-terminated

It’s sufficient to place the caret after line 29 and add .map to trigger this issue.

Environment:

  • Visual Studio Code v1.105.1
  • rust-analyzer v0.3.2660
  • macOS 26.0.1 running on an M1 Pro

Note: I was conflicted where to submit this issue and I was torn between this project and https://github.com/rust-lang/rust-analyzer but eventually thought that it would be wiser to start with nom. After all you have more insights into what these functions do and can possibly narrow it down further. I will be happy to submit an issue with rust-analyzer if you could provide me with some guidance to help the folks over there to pinpoint the root cause.

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