Skip to content

Avoid quadratic duplicate-attribute check in ParseAttributes - #1105

Open
darshan-mog wants to merge 1 commit into
leethomason:masterfrom
darshan-mog:attribute-dup-hash
Open

darshan-mog wants to merge 1 commit into
leethomason:masterfrom
darshan-mog:attribute-dup-hash

Conversation

@darshan-mog

Copy link
Copy Markdown

XMLElement::ParseAttributes rejects repeated attributes by calling Attribute() for each new one, which walks every attribute parsed so far, so a single element with N attributes costs O(N^2) string compares inside Parse(). A 1 MB document that is one element with 100k unique attributes (<r a0='' a1='' ...) took 14.6 s to parse here at -O2 and now takes 4.3 ms (10k attributes: 146 ms to 0.5 ms, 40k: 2.3 s to 2.0 ms). Elements with up to 16 attributes keep the existing linear check; past that the names go into an open-addressed hash set built on DynArray, so a duplicate is still reported as XML_ERROR_PARSING_ATTRIBUTE at the same attribute.

This branch has not been deployed

No deployments
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