Skip to content

Commit e234749

Browse files
committed
perf: increase preallocate_node_capacity
1 parent b4657e4 commit e234749

File tree

7 files changed

+15
-15
lines changed

7 files changed

+15
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn main() -> Result<(), css_inline::InlineError> {
9797
- `base_url`. The base URL used to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `None`
9898
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `true`
9999
- `extra_css`. Extra CSS to be inlined. Default: `None`
100-
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `8`
100+
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `32`
101101

102102
You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="ignore"` attribute to it:
103103

bindings/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ inliner.inline("...")
113113
- `base_url`. The base URL used to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `None`
114114
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `True`
115115
- `extra_css`. Extra CSS to be inlined. Default: `None`
116-
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `8`
116+
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `32`
117117

118118
You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="ignore"` attribute to it:
119119

bindings/python/src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn parse_url(url: Option<String>) -> PyResult<Option<url::Url>> {
6767
})
6868
}
6969

70-
/// CSSInliner(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
70+
/// CSSInliner(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)
7171
///
7272
/// Customizable CSS inliner.
7373
#[pyclass]
@@ -78,7 +78,7 @@ struct CSSInliner {
7878
#[pymethods]
7979
impl CSSInliner {
8080
#[new(
81-
text_signature = "(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
81+
text_signature = "(keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)"
8282
)]
8383
fn new(
8484
keep_style_tags: Option<bool>,
@@ -94,7 +94,7 @@ impl CSSInliner {
9494
base_url: parse_url(base_url)?,
9595
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
9696
extra_css: extra_css.map(Cow::Owned),
97-
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
97+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(32),
9898
};
9999
Ok(CSSInliner {
100100
inner: rust_inline::CSSInliner::new(options),
@@ -118,12 +118,12 @@ impl CSSInliner {
118118
}
119119
}
120120

121-
/// inline(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
121+
/// inline(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)
122122
///
123123
/// Inline CSS in the given HTML document
124124
#[pyfunction]
125125
#[pyo3(
126-
text_signature = "(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
126+
text_signature = "(html, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)"
127127
)]
128128
fn inline(
129129
html: &str,
@@ -140,18 +140,18 @@ fn inline(
140140
base_url: parse_url(base_url)?,
141141
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
142142
extra_css: extra_css.map(Cow::Borrowed),
143-
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
143+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(32),
144144
};
145145
let inliner = rust_inline::CSSInliner::new(options);
146146
Ok(inliner.inline(html).map_err(InlineErrorWrapper)?)
147147
}
148148

149-
/// inline_many(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)
149+
/// inline_many(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)
150150
///
151151
/// Inline CSS in multiple HTML documents
152152
#[pyfunction]
153153
#[pyo3(
154-
text_signature = "(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=8)"
154+
text_signature = "(htmls, keep_style_tags=False, keep_link_tags=False, base_url=None, load_remote_stylesheets=True, extra_css=None, preallocate_node_capacity=32)"
155155
)]
156156
fn inline_many(
157157
htmls: &PyList,
@@ -168,7 +168,7 @@ fn inline_many(
168168
base_url: parse_url(base_url)?,
169169
load_remote_stylesheets: load_remote_stylesheets.unwrap_or(true),
170170
extra_css: extra_css.map(Cow::Borrowed),
171-
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(8),
171+
preallocate_node_capacity: preallocate_node_capacity.unwrap_or(32),
172172
};
173173
let inliner = rust_inline::CSSInliner::new(options);
174174
inline_many_impl(&inliner, htmls)

bindings/wasm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var inlined = inline(
7979
- `base_url`. The base URL used to resolve relative URLs. If you'd like to load stylesheets from your filesystem, use the `file://` scheme. Default: `null`
8080
- `load_remote_stylesheets`. Specifies whether remote stylesheets should be loaded. Default: `true`
8181
- `extra_css`. Extra CSS to be inlined. Default: `null`
82-
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `8`
82+
- `preallocate_node_capacity`. **Advanced**. Preallocates capacity for HTML nodes during parsing. This can improve performance when you have an estimate of the number of nodes in your HTML document. Default: `32`
8383

8484
You can also skip CSS inlining for an HTML tag by adding the `data-css-inline="ignore"` attribute to it:
8585

bindings/wasm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl TryFrom<Options> for rust_inline::InlineOptions<'_> {
101101
base_url: parse_url(value.base_url)?,
102102
load_remote_stylesheets: value.load_remote_stylesheets,
103103
extra_css: value.extra_css.map(Cow::Owned),
104-
preallocate_node_capacity: value.preallocate_node_capacity.unwrap_or(8),
104+
preallocate_node_capacity: value.preallocate_node_capacity.unwrap_or(32),
105105
})
106106
}
107107
}

css-inline/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Default for InlineOptions<'_> {
137137
base_url: None,
138138
load_remote_stylesheets: true,
139139
extra_css: None,
140-
preallocate_node_capacity: 8,
140+
preallocate_node_capacity: 32,
141141
}
142142
}
143143
}

css-inline/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ OPTIONS:
121121
base_url,
122122
load_remote_stylesheets: args.load_remote_stylesheets,
123123
extra_css: args.extra_css.as_deref().map(Cow::Borrowed),
124-
preallocate_node_capacity: 8,
124+
preallocate_node_capacity: 32,
125125
};
126126
let inliner = CSSInliner::new(options);
127127
if args.files.is_empty() {

0 commit comments

Comments
 (0)