Skip to content
Source
Sign inSign up
TanStack/highlight

perf: bound impossible markup tag scans at EOF #50

Mergedtannerlinsleymerged 1 commit intomain fromtaren/highlight-markup-eof-boundmerged by tannerlinsley

tannerlinsleycommented

Repeated unclosed tag prefixes make markup recovery rescan the remaining suffix for every possible tag. Cache the input's last possible closing angle bracket lazily, then skip only tag-end scans that cannot succeed. Keep the tag-name regex calls and the existing comment, EJS and inner-tag recovery paths.

Repeated matched minified browser bundles, complete UTF-8 HTML consumption, Node 24.15.0 and Bun 1.3.14: 2,048 unclosed <a prefixes improve from about 10.7 ms to 0.14 ms on Node, a 98.7% time reduction, and improve about 98.2% on Bun. A long unterminated attribute improves about 55% on Node and 90% on Bun. Ordinary markup docs and valid sparse/dense controls vary around neutral, no universal throughput claim. Fresh-process first completed malformed highlight improves from 9.48 ms to 0.93 ms on Node, import and the TypeScript control remain effectively unchanged.

Three allocation pairs for completed malformed-prefix tokenization change +0.20%, +0.33% and +0.80%; HTML changes -0.77%, -0.97% and +0.62%. Allocation is effectively unchanged. A much smaller allocation control has sampling noise, no reduction is claimed. Nine fresh settled-retained pairs show no material increase. There is no new per-token buffer or cross-call cache.

Validation: all 12 local production gates, 377 tests, 66 unchanged size/import contracts and 20 runtime budgets pass. Exact public behavior passes 114,598 quote/escape cases on each engine plus 17,498 general cases. Raw range order, context calls, nested reentry, overflow-shaped and malformed inputs pass 12,216 additional cases on each engine. Regression coverage keeps unterminated comments and EJS regions after bad prefixes, discovers inner tags inside an unclosed outer quote, and preserves escaped source.

The current C-language composition also passes its original budgets in an isolated source copy, all-language gzip 27,978 / 28,000 and Brotli 24,934 / 25,000 bytes. The factory snapshot was not modified. Main docs Brotli remains 5,794 / 5,800 bytes. No API, language, dependency, authoring or budget changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved syntax highlighting recovery for malformed HTML and EJS markup, preserving tokens and detecting inner tags when tag endings or quoted attributes are incomplete.
    1. 🦋 Changeset detected

      Latest commit: a25b48b34ea0ae5b37b8c893ce63a2758a98a795

      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: 212307df-c3b8-49c6-8498-381bbfcc6437
      Commits

      Reviewing files that changed from the base of the PR and between b9a7363278567928dbf872f289e498334288aeba and a25b48b34ea0ae5b37b8c893ce63a2758a98a795.

      Files selected for processing: 3
      • .changeset/markup-eof-bound.md
      • src/internal/markup.ts
      • test/markup-recovery.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 markup scanner now bounds tag-end searches using the position of the final > in the source. New tests cover recovery and token preservation for malformed HTML and EJS input.

      Changes: Markup recovery

      Layer / File(s)Summary
      Bounded tag-end search and recovery tests
      src/internal/markup.ts, test/markup-recovery.test.ts, .changeset/markup-eof-bound.md
      collectMarkupRanges passes the final > position to findTagEnd, which returns -1 when the search starts beyond that position. Tests cover repeated unclosed tag prefixes, unfinished comments and EJS regions, and inner tags inside an unclosed quoted attribute. The changeset records a patch release entry for @tanstack/highlight.

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

      Change: Refactor

      Merge Risk: Minimal · up to a25b4

      No actionable merge-blocking risk was found in the changed markup recovery logic or its tests.

      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: preventing impossible markup tag scans at EOF.
      Description checkPassedThe description provides detailed change rationale and validation results. It covers the template content, although it does not use the template's explicit "## Changes" and "## Validation" headings.
      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 2 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 this01e5bf0

    4. tannerlinsley closed this

Sign in to join this conversation.