Skip to content

Report pest's slow multi-line errors upstream, then drop Citry's workaround #354

Open

Description

@JuroOravec

Building a parse error for a span that covers many lines takes time proportional to the number of lines times the length of the whole input. #338 avoids it in Citry; this issue tracks reporting the root cause to pest and removing the avoidance once pest is fixed.

What happens in pest

pest::error::Error::new_from_span (pest 2.8.3) walks every line of the error span through Span::lines(). Each step of that iterator calls find_line_start and find_line_end, which scan the input from the span's position, not from where the previous line ended. So building one error costs about (lines in the span) × (input length).

Measured in Citry before #338, on an expression error whose span covered the whole template:

Lines in the span Time
1,000 0.1 s
4,000 2.8 s
20,000 75 s

What Citry does today

ParseError::from_span (crates/citry_template_parser/src/error.rs) builds a long span's pest error from a copy that holds only the span's first and last lines, so the error text is byte-identical and the cost is linear. A test compares the output with pest's own for every span of 400 random inputs, and a scaling test checks that a 20,000-line span takes under a second.

The ticket to open upstream

Open it at https://github.com/pest-parser/pest/issues:

  • Title: Error::new_from_span is quadratic in the number of lines in the span
  • Body: the explanation above, plus a minimal reproduction: a grammar that fails on input of N lines with a span covering all of it, timed for N = 1,000, 4,000 and 20,000.
  • Suggested fix: make the Span::lines() iterator (LinesSpan) carry the end of the previous line forward, so each line is found in time proportional to its own length. Alternatively, have new_from_span find only the lines it prints.

When pest ships a fix and Citry upgrades to it, remove the workaround in ParseError::from_span and keep the scaling test.

Activity

  1. added
    next-sprint
    on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    next-sprint

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions