perf(formatter_markdown): bump parser to 0.0.4 and skip unread work (#28713)

- bump oxc-markdown-parser 0.0.4 which skips autolink literal attempts that cannot match
- Compute a text's next words only under `proseWrap: always`, the only mode that reads them
- Print link destinations with nothing to escape as is

About 15% CPU instruction reduction.
This commit is contained in:
leaysgur committed 2026-11-02 08:26:19 +00:00
1 parent 633ee960da
commit b6f1ac9b05
5 files changed
+31 -7

No files matched your search

Generated
+2 -2
View File
@@ -1709,9 +1709,9 @@ dependencies = [
[[package]]
name = "oxc-markdown-parser"
version = "0.0.3"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e76cbb946bcc0c6fc03f13b11ae0055864804152114dc7dcae5ede8b6d59ad83"
checksum = "13691b88414d375b51238d171794143303f676ced5a600f8f64e6f7fa4271ba3"
dependencies = [
"oxc_allocator",
]
+1 -1
View File
@@ -244,7 +244,7 @@ num-traits = "0.2.19" # Numeric traits
oxc-css-parser = "0.0.19" # CSS/SCSS/Less parser (raffia 0.12.3 fork: adds `template_placeholder` typed placeholders for css-in-js + valid-syntax coverage fixes (see crates/oxc_formatter_css/AGENTS.md))
oxc-graphql-parser = "0.0.9" # GraphQL parser (direct AST; apollo-parser 0.8.6 fork aligned with graphql-js 17 syntax)
oxc-htmlish-parser = "0.0.2" # HTML / Vue / Angular parser (loose, span-faithful AST)
oxc-markdown-parser = "0.0.3" # CommonMark + GFM parser (span-faithful, style-preserving typed AST)
oxc-markdown-parser = "0.0.4" # CommonMark + GFM parser (span-faithful, style-preserving typed AST)
oxc-toml = "0.15.1" # TOML parser and formatter
oxc-yaml-parser = "0.0.8" # YAML 1.2 parser (comment-preserving typed AST, node naming from `yaml-unist-parser`)
papaya = { version = "0.2.5", default-features = false } # Concurrent hash map
@@ -340,6 +340,9 @@ pub fn collect_inlines<'a>(
parts.push_str("\\");
}
let autolink_stretch = autolink_stretch(children, i, raw);
// A text never spans a line, so only `always` breaks its whitespace
// and reads the words a break would put at a line start
let always = f.options().prose_wrap == ProseWrap::Always;
let cx = words::TextContext {
autolink_stretch,
first_of_delimiter: parent.delimiter.filter(|_| i == 0),
@@ -352,8 +355,20 @@ pub fn collect_inlines<'a>(
),
after_liquid: follows_liquid(children, i),
before_soft_break: matches!(children.get(i + 1), Some(Inline::SoftBreak(_))),
next_word: next_word_of(children, i, parent.delimiter, f),
glued_last_word: glued_last_word(children, i, raw, f),
last_on_line: matches!(
children.get(i + 1),
None | Some(Inline::SoftBreak(_) | Inline::HardBreak(_))
),
next_word: if always {
next_word_of(children, i, parent.delimiter, f)
} else {
None
},
glued_last_word: if always {
glued_last_word(children, i, raw, f)
} else {
None
},
has_cjk,
..words::TextContext::default()
};
@@ -2,8 +2,11 @@
//! destinations and titles are re-derived from their cooked values,
//! reference forms other than `[text][label]` are re-emitted from the source.
use std::borrow::Cow;
use oxc_allocator::StringBuilder;
use oxc_formatter_core::{
arena_cow_str,
builders::{group, indent, soft_line_break_or_space, text, token},
write,
};
@@ -198,7 +201,7 @@ fn print_label<'a>(pieces: &[Segment], f: &MarkdownFormatter<'_, 'a>) -> &'a str
/// a control character, a leading `<`, or parentheses;
/// definitions tolerate balanced parentheses (CommonMark: nested up to three deep)
fn print_url<'a>(
url: &str,
url: &Cow<'a, str>,
unwrap_balanced_parens: bool,
f: &MarkdownFormatter<'_, 'a>,
) -> &'a str {
@@ -210,6 +213,10 @@ fn print_url<'a>(
} else {
url.contains(['(', ')'])
};
// Nothing to escape: the (usually borrowed) url prints as is
if !needs_brackets && !bytes.iter().any(|&b| matches!(b, b'\\' | b'&')) {
return arena_cow_str(url, f);
}
let mut out = StringBuilder::with_capacity_in(url.len() + 2, f.allocator());
if needs_brackets {
out.push('<');
@@ -68,6 +68,8 @@ pub struct TextContext<'a> {
pub after_liquid: bool,
/// The next sibling is a soft break (the text ends a source line).
pub before_soft_break: bool,
/// Nothing follows the text on its source line (the next sibling is a line break, or there is none).
pub last_on_line: bool,
/// The first word the next sibling starts, for the whitespace that ends this text.
pub next_word: Option<NextWord<'a>>,
/// The text's last word with the nodes glued after it on the source line (`:-:` + `[[w]]`),
@@ -153,7 +155,7 @@ pub fn push_text<'a>(
&& !leading_ws
&& cx.after_soft_break
// Alone on its line: a node after it (`== `x``) makes the line text
&& cx.next_word.is_none()
&& cx.last_on_line
&& is_fake_setext_underline(word)
{
Cow::Owned(format!("\\{word}"))