Skip to content

Convert hotpath optimizations - #75

Merged
letmutex merged 7 commits into
mainfrom
perf/convert-hotpath-microopts
Jul 11, 2026
Merged

letmutex merged 7 commits into
mainfrom
perf/convert-hotpath-microopts

Conversation

@letmutex

@letmutex letmutex commented Jul 11, 2026 •

Copy link
Copy Markdown
Owner

The optimizations from AI show a 3.9% improvement in the benchmark result:

15.401ms -> 14.794ms

Summary by CodeRabbit

  • Performance

    • Improved HTML-to-Markdown conversion efficiency by reducing temporary allocations during parsing and serialization.
    • Faster processing for whitespace normalization, inline code formatting, and Markdown character escaping.
  • Compatibility

    • Preserved existing output while refining edge-case handling for newlines, leading spaces, and Markdown marker escaping (including ordered lists).
  • Refactor

    • Streamlined internal tag/selector handling and simplified whitespace detection logic.

letmutex added 6 commits July 11, 2026 22:46
Feed the parser with one-shot UTF-8 input, trim markdown buffers in place,
and tighten escape/merge/code scanning to cut Wikipedia convert latency by
about 3% on the convert_bench harness.
Replace wip placeholders from the convert hot-path optimization session.
Use the join_blocks newline-count idiom instead of byte-scan helpers,
name the markdown buffer capacity hint, clarify pre-escape marker
decisions, and scan inline-code backticks with a plain enumerate loop.
String::new() is within noise of with_capacity(4096) on convert_bench,
so keep the simpler allocation.
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR refactors Markdown text processing, parent-tag selector handling, HTML parsing, and output trimming to use slices, byte scans, and in-place string operations.

Changes

String and parsing allocation cleanup

Layer / File(s) Summary
Markdown text processing
src/dom_walker.rs, src/element_handler/code.rs, src/text_util.rs
Text normalization, Markdown escaping, inline-code delimiter detection, and whitespace classification use direct string or byte operations.
Parent selector slice contract
src/element_handler/*, src/node_util.rs
Parent-tag APIs and handler call sites use borrowed slices instead of vector references; child collection is simplified.
Document parsing and output trimming
src/lib.rs
HTML parsing uses the one-shot input path, and boundary newlines are removed in place from generated Markdown.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

  • letmutex/htmd#63: Overlaps in element_handler call paths and parent-handler interfaces.
  • letmutex/htmd#74: Overlaps in src/lib.rs HTML tree parsing and Markdown newline handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately reflects the performance-focused hotpath optimization changes in the PR.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/convert-hotpath-microopts

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

Comment @coderabbitai help to get the list of available commands.

@letmutex letmutex changed the title Perf/convert hotpath microopts Convert hotpath optimizations Jul 11, 2026
Use char::is_ascii_digit instead of a manual '0'..='9' match.
@letmutex
letmutex merged commit a36f2d3 into main Jul 11, 2026
1 check passed
@letmutex
letmutex deleted the perf/convert-hotpath-microopts branch July 11, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant