Skip to content

Tokenize named character references using a DAFSA #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

simonwuelker
Copy link
Contributor

@simonwuelker simonwuelker commented Jul 23, 2025

Currently named character references are implemented using a phf map that is repeatedly queried for each character. This works, but has suboptimal performance.

Traversing a DAFSA that is generated at compile time makes tokenizing named character references 30% faster. This technique is described in https://www.ryanliptak.com/blog/better-named-character-reference-tokenization/. For illustration, a reduced version of the dafsa is can be viewed here.

Apologies for the big change. If it's too hard to review we could also merge the DAFSA incrementally. Most of the diff is the list of named entities being moved around and a benchmark file being added.

I have not looked into how this affects the binary size. Some more savings are possible by packing the array of result characters.

Do not merge yet - needs servo companion PR.

This is non-breaking change for html5ever and a breaking change for web_atoms, as the list of named character references no longer lives there.

@simonwuelker simonwuelker added the V-breaking Breaking change label Jul 23, 2025
@simonwuelker simonwuelker force-pushed the charref branch 2 times, most recently from 729b0d4 to 32ecdef Compare July 23, 2025 17:31
@simonwuelker simonwuelker marked this pull request as draft July 23, 2025 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
V-breaking Breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant