Skip to content
Source
Sign inSign up
TanStack/highlight

perf: apply Markdown annotations directly to line nodes #66

Opentannerlinsleywants to merge 3 commits intomain fromtaren/highlight-direct-line-annotationsopened

tannerlinsleycommented

Markdown line annotations currently scan all annotations for every line. This uses the owned line-wrapper/newline layout to apply the same ordered classes directly, preserving duplicates, diff order, malformed-input fallback, getter order and escaping.

Valid 4,000-line annotation rendering is 97.15–97.26% faster in Node and 87.13–87.76% faster in Bun, measuring completed HTML plus UTF-8. Three fresh allocation pairs use 25.74–26.30% less sampled JavaScript allocation on that case and 1.23–1.44% less on the selected 334-document corpus. Plain/numbered corpus work stays near neutral. These are workload-specific measurements with A/A controls and fresh reversed processes.

402 tests, Node/Bun differential checks, all non-size composed gates, and actual installed Node 18/20/22/24/26 checks pass. Each Node imports all 100 exports, runs bounded hostile inputs and passes 1,004 exact Markdown checks against the published baseline. All 216 package dist files match the release except markdown.js. Actual unbundled startup A/A checks show no material first-corpus regression.

Owner decision requested, not ready to merge. Main adapter is 2,503 gzip / 2,303 Brotli bytes; composed adapter is 2,500 / 2,305. Current caps are 2,500 / 2,300. Approval was requested for exact caps of 2,503 / 2,305, with every other budget unchanged. Main adapter growth versus release is 90 gzip / 84 Brotli bytes. The repeated Node stress case has a 5.4 MiB median peak-RSS increase despite lower live heap; this tradeoff is included in the decision request. No budgets have changed.

The shared-render-call follow-up was rejected after direct comparisons found worse compressed size and no consistent runtime benefit. Final runtime and tests are byte-identical to the source reviewed at edb446. CodeRabbit's only finding was the existing size failure. Any approved limit update still needs normal current-head CI, runtime checks and review before protected merge and release.

    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 2423733df300f1f67688c8895b2a74290b536db0

      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 →
      Walkthrough

      The Markdown highlighter now uses a specialized rendering path when every decoration specifies a numeric line. Regression tests cover annotation ordering, token access, and line-boundary cases.

      Changes: Markdown line annotations

      Layer / File(s)Summary
      Line rendering and validation
      src/markdown.ts, test/markdown-annotation-index.test.ts, .changeset/indexed-markdown-lines.md
      When every decoration specifies a numeric line, the highlighter renders line-numbered nodes and adds each decoration class to its target line. Tests cover class ordering, duplicate highlights, token access, and empty or invalid lines. The changeset records a patch for @tanstack/highlight.

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

      Change: Refactor

      Merge Risk: Moderate · up to edb44

      The Markdown line-annotation change gives large speedups on big annotated blocks, but it pushes the adapter over its enforced size limits. CI verification currently fails and publication cannot proceed. Reduce the bundle size or get an explicit budget exception before merging.

      Pre-merge checks: Passed 5
      Check nameStatusExplanation
      Title checkPassedThe title "perf: apply Markdown annotations directly to line nodes" matches the main change in the changeset. The raw summary and objectives say annotation classes are now applied directly to adapter-…
      Docstring CoveragePassedNo eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
      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.
      Description checkPassedThe description gives a clear, specific account of the change: direct application of ordered Markdown annotation classes to owned line nodes instead of scanning all annotations per line. It covers pre…
      Full details: Title check

      Explanation

      The title "perf: apply Markdown annotations directly to line nodes" matches the main change in the changeset. The raw summary and objectives say annotation classes are now applied directly to adapter-owned line nodes instead of scanning every annotation for every rendered line. The title is concise, specific, and uses a conventional perf: prefix.

      Full details: Docstring Coverage

      Explanation

      No eligible functions found in the changed files. Skipping docstring coverage check. 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 0 functions across 2 files. (1 skipped: 1 unsupported.)

      Full details: Description check

      Explanation

      The description gives a clear, specific account of the change: direct application of ordered Markdown annotation classes to owned line nodes instead of scanning all annotations per line. It covers preserved behavior (duplicates, diff order, malformed-input fallback, getter order, escaping), measured performance and allocation results with methodology, test and compatibility results, and size-budget status. It does not follow the repository template. The required '## Changes' section is present in substance but is not labelled, and it does not explain why the change belongs in a small docs highlighter. The '## Validation' section is present in substance and includes size/benchmark results, but it does not list focused fixtures by name. The description is also long, and it states the PR is not ready to merge and that a size-budget decision is pending. Those points are relevant context and do not make the description incomplete.

      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

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      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: 955506b1-9f01-4888-bad3-12d50d70383a
      Commits

      Reviewing files that changed from the base of the PR and between 59cc1d177a6b9b7797a66ca741491fef4af88a96 and edb446e077c99819e78c626e51e4fb9075d83a03.

      Files selected for processing: 3
      • .changeset/indexed-markdown-lines.md
      • src/markdown.ts
      • test/markdown-annotation-index.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.

      • Fix comments: Fix CodeRabbit comments on this PR

Sign in to join this conversation.