Skip to content

Comments

Avoid reallocations for reading qualified names#68

Merged
kornelski merged 1 commit intokornelski:mainfrom
drott:qualNameAllocLand
Jan 23, 2026
Merged

Avoid reallocations for reading qualified names#68
kornelski merged 1 commit intokornelski:mainfrom
drott:qualNameAllocLand

Conversation

@drott
Copy link

@drott drott commented Jan 22, 2026

Qualified names accumulate into buf, but drop their scratch space after every completion of reading a qualified name. At the end of reading a qualified name, the scratch space only needs to be read by reference. The allocation of the value returned to the API client happens in OwnedName.

By using a separate scratch space qualified_name_buf, we can operate on the same scratch space string for each time reading a qualified name.

@drott drott force-pushed the qualNameAllocLand branch from c4ab9c3 to c7fe1f4 Compare January 22, 2026 16:00
@drott
Copy link
Author

drott commented Jan 22, 2026

Running https://github.com/drott/xml-rs/blob/parserBench/tests/streaming.rs#L235 on my machine this gives me a 2.8% improvement in runs per second on running this parsing benchmark that is similar to the one we use for Blink.

The existing allocation in read_qualified_name:

image

is gone:

image

@drott drott force-pushed the qualNameAllocLand branch from c7fe1f4 to 456c198 Compare January 22, 2026 16:04
@drott
Copy link
Author

drott commented Jan 22, 2026

Looks like there are still correctness issues, I'll look into that.

@drott drott force-pushed the qualNameAllocLand branch from 456c198 to 57055e6 Compare January 23, 2026 11:19
Qualified names accumulate into buf, but drop their scratch space after
every completion of reading a qualified name. At the end of reading a
qualified name, the scratch space only needs to be read by
reference. The allocation of the value returned to the API client
happens in OwnedName.

By using a separate scratch space `qualified_name_buf`, we can operate
on the same scratch space string for each time reading a qualified name.

Results in a 2.8% speedup in a local measurement against a test similar
to [1].

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/perf_tests/parser/xml-parser.html;l=8?q=xml-parser.html
@drott drott force-pushed the qualNameAllocLand branch from 57055e6 to 031ec9c Compare January 23, 2026 11:28
@drott
Copy link
Author

drott commented Jan 23, 2026

I believe this is ready for review now.

@kornelski kornelski merged commit f2054c5 into kornelski:main Jan 23, 2026
2 checks passed
mohd-akram pushed a commit to gsource-mirror/chromium-src-third_party-rust that referenced this pull request Feb 4, 2026
Changes merged in upstream but no version released yet.

Covers kornelski/xml-rs#68

Bug: 470367156
Change-Id: I1e2b729c7e2e61aff25b6c84e75f298718061df2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7544561
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Auto-Submit: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1579537}
NOKEYCHECK=True
GitOrigin-RevId: f41e0fc863c04deab1f3e4bb3be97251842b87cc
jenkins-chromium-github-sync bot pushed a commit to armarok/chromium that referenced this pull request Feb 4, 2026
Changes merged in upstream but no version released yet.

Covers kornelski/xml-rs#68

Bug: 470367156
Change-Id: I1e2b729c7e2e61aff25b6c84e75f298718061df2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7544561
Reviewed-by: Łukasz Anforowicz <lukasza@chromium.org>
Auto-Submit: Dominik Röttsches <drott@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1579537}
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.

2 participants