Skip to content
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

Avoid re-validating the same attribute name multiple times #8668

Closed

Conversation

@fitzgen
Copy link
Member

fitzgen commented Nov 24, 2015

If the name given to setAttribute names an attribute that already exists, then
it must have already been validated as a valid attribute name. In this case, we
can skip validation, which shows up fairly heavily on profiles.

Dromaeo DOM attributes is largely unchanged: From 2721.35 runs/s to 2727.40 runs/s.

setAttribute in a loop (micro benchmark from #8645) gets a little bump: From 4540 ms to 4400 ms.

Depends on #8645.

Not 100% clear this is a valid optimization, see #6906 (comment).

Given that, and the relatively lackluster speedups, this may not be worth merging.

Review on Reviewable

fitzgen added 2 commits Nov 22, 2015
Interning a DOMString as an atom can be expensive, and that work is unnecessary
if the attribute being added already exists and already has an interned
name. Instead of eagerly interning, first do a linear search over the existing
attributes to see if we can skip interning. This is an optimization that Gecko
already employs, as described in #6906.

I tested Dromaeo's dom subsuite and a super naive micro benchmark of my own
writing.

I haven't looked at Dromaeo's code, but given the units it reports, I'm assuming
that higher is better.

For my super naive micro benchmark, smaller is better.

Here are the results:

+---------+-------------------------+----------------------+----------------+
|         | Servo w/out this commit | Servo w/ this commit | Gecko          |
+---------+-------------------------+----------------------+----------------+
| Dromaeo | 2684.37 runs/s          | 2771.50 runs/s       | 2068.78 runs/s |
+---------+-------------------------+----------------------+----------------+
| Micro   | 4985 ms                 | 4606 ms              | 1616 ms        |
+---------+-------------------------+----------------------+----------------+

So this seems to yield a slight performance increase, but nothing to write home
about. This could potentially hurt performance when there are many attributes or
if the attribute names are very long; intuitively, neither seem super common to
me.

Here is the source of my super naive micro benchmark:

```html
<!DOCTYPE html>
<body>
    <button onclick="run()">Test</button>
    <h1 id="result"></h1>
    <script>
        function run() {
            var h1 = document.getElementById("result");
            var start = Date.now();
            var i = 10000000;
            while (i--) {
                h1.setAttribute("foobar", "baz");
            }
            h1.textContent = Date.now() - start;
        }
    </script>
</body>
```
If the name given to setAttribute names an attribute that already exists, then
it must have already been validated as a valid attribute name. In this case, we
can skip validation, which shows up fairly heavily on profiles.
@asajeffrey
Copy link
Member

asajeffrey commented Nov 24, 2015

I agree that since the performance numbers aren't great, this may not be worth merging.

@Ms2ger Ms2ger self-assigned this Nov 25, 2015
@bors-servo
Copy link
Contributor

bors-servo commented Nov 25, 2015

The latest upstream changes (presumably #8667) made this pull request unmergeable. Please resolve the merge conflicts.

@nox nox assigned nox and unassigned Ms2ger Feb 26, 2016
@nox
Copy link
Member

nox commented Feb 26, 2016

Given the discussion linked in #6906 (comment), it seems postponing the validity check of name is not spec-compliant. Closing this. Thanks for your work nonetheless!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.