Skip to content
Source
Sign inSign up
TanStack/highlight

perf: avoid prefix matches in YAML block scalars #58

Mergedtannerlinsleymerged 1 commit intomain fromrefs/pull/58/headmerged by tannerlinsley

tannerlinsleycommented

YAML block scalars now classify each line once with trimStart() and derive indentation from its length, avoiding a second scan and prefix match allocation. Scalar boundaries, trailing whitespace, Unicode whitespace, CRLF handling and raw range order stay the same. Adds five regression cases.

Measured complete HTML plus UTF-8 output in repeated alternating runs on macOS ARM64, Node 24.15.0 and Bun 1.3.14: large valid scalars take about 8% less time on Node and 11% less on Bun, with about 74% less sampled JavaScript allocation in three fresh process pairs. Scalars containing indented header-like text improve about 40–47%. Full-corpus controls are mixed and do not establish a universal speedup. Cold tiny/blank controls are near noise, with small Node losses and neutral or faster Bun results; retained heap is unchanged.

Validation: full local checks, all 66 original size profiles and 20 runtime budgets, the composed C compatibility checks, exact differential behavior checks on Node and Bun, and actual packed consumers on Node 18/20/22/24/26. No budget or dependency changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved YAML block scalar boundary detection, including for blank lines, Unicode indentation, and different line endings.
  • Tests
    • Added coverage for YAML block scalar ranges and string classification.
    1. 🦋 Changeset detected

      Latest commit: 8a638f7a29ac24c9a3101c73ce2c7516a97e991a

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/highlightPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: fbe8b0cd-d7b7-4d83-b9c9-5b810d0a03ec
      Commits

      Reviewing files that changed from the base of the PR and between 07774464eb6a2c523f982f585e5cf83efa522edb and 8a638f7a29ac24c9a3101c73ce2c7516a97e991a.

      Files selected for processing: 3
      • .changeset/yaml-scalar-prefix.md
      • src/languages/yaml.ts
      • test/yaml-block-scalar.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

      Walkthrough

      The YAML tokenizer now uses leading indentation to detect block scalar boundaries. New tests cover line endings, whitespace, Unicode indentation, nested scalars, and scalar classifications. A patch changeset records the update.

      Changes: YAML block scalar handling

      Layer / File(s)Summary
      Boundary detection and coverage
      src/languages/yaml.ts, test/yaml-block-scalar.test.ts, .changeset/yaml-scalar-prefix.md
      The boundary check uses trimStart() to determine content indentation. Tests cover scalar ranges with LF and CRLF endings, whitespace, Unicode indentation, nested scalars, and other line separators. The changeset records a patch release entry.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Refactor

      Merge Risk: Minimal · up to 8a638

      The indentation optimization has no identified merge-blocking issue.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main performance change: avoiding prefix matches in YAML block scalars.
      Description checkPassedThe description explains the behavior change, motivation, regression coverage, validation results, benchmark context, and scope. It satisfies both required template sections.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files. (1 skipped: 1 unsupported.)

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Finishing Touches
      Generate docstrings
      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share
    3. tannerlinsley merged thisb32f26d

    4. tannerlinsley closed this

Sign in to join this conversation.