Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Move towards more efficient DOM manipulation#900

Merged
leroix merged 3 commits intoatom:masterfrom
leroix:faster-rendering
Oct 5, 2017
Merged

Move towards more efficient DOM manipulation#900
leroix merged 3 commits intoatom:masterfrom
leroix:faster-rendering

Conversation

@leroix
Copy link
Contributor

@leroix leroix commented Oct 5, 2017

Description of the Change

This PR moves away from setting .innerHTML in .renderItem where possible. Though, when we receive HTML via the suggestion provider API, we still have to use it. Direct DOM manipulation tends to be faster when called in a loop:
screen shot 2017-10-03 at 11 05 19 pm

screen shot 2017-10-03 at 11 05 46 pm

Here's an illustration of the improvement for the same autocomplete scenario before and after the changes in this PR:
screen shot 2017-10-04 at 6 49 01 pm
screen shot 2017-10-04 at 6 48 04 pm

Alternate Designs

n/a

Benefits

This is a step towards faster rendering of autocomplete suggestions making the typing experience feel more responsive.

Possible Drawbacks

Imperative dom manipulation can potentially be more complex than just setting .innerHTML in some cases.

Applicable Issues

n/a

@maxbrunsfeld
Copy link
Contributor

maxbrunsfeld commented Oct 5, 2017

⚡ Great to see that big of a speed improvement!

Code looks good to me, though I've never worked on this code before.

}

getDisplayHTML (text, snippet, displayText, replacementPrefix) {
getDisplay (text, snippet, displayText, replacementPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nitpick: This name is a bit weird to me. getElement maybe?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's already called "element" in terms of element in the list, so my suggestion isn't good.

@nathansobo nathansobo changed the title move towards more efficient DOM manipulation Move towards more efficient DOM manipulation Oct 5, 2017
Copy link
Contributor

@nathansobo nathansobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your approach to updating the tests. If the test coverage was good previously, then this should be fine. There was quite a bit of logic for constructing the elements and I'd be lying if I looked at each line super closely, but from a few minutes of inspection it all seems reasonable. I say we move forward with this. Nice work!

@nathansobo
Copy link
Contributor

It's probably unrelated to the content of this PR, but What's up with the subsequence provider failing against beta on AppVeyor? Did we change the behavior?

@leroix
Copy link
Contributor Author

leroix commented Oct 5, 2017

@nathansobo Yea, that's what I'm looking into today. I don't think we've changed the behavior that I know of. I'm a bit befuddled.

Btw, I don't really like getDisplay either. I was just having trouble thinking of something better.

@leroix
Copy link
Contributor Author

leroix commented Oct 5, 2017

I just built 1.22.0-beta0 locally, ran the specs, and didn't get the failure that was present in Appveyor. 😕

}

getDisplay (text, snippet, displayText, replacementPrefix) {
getDisplayFrag (text, snippet, displayText, replacementPrefix) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a pain, but we prefer to use whole words in all Atom code unless there's a very special case. (Like "id")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

@leroix leroix force-pushed the faster-rendering branch 5 times, most recently from 6cf0977 to 70e1cbd Compare October 5, 2017 19:22
@leroix
Copy link
Contributor Author

leroix commented Oct 5, 2017

We figured out that appveyor is failing because of an ambiguity in the sorting logic in https://github.com/atom/superstring/blob/master/src/core/text-buffer.cc#L525

If the scores are the same, the order is left up to the order the matches showed up in unordered_map which is platform-dependent.

The fix for this is unrelated to this PR, so I think this PR is ready to go.

@leroix leroix merged commit 8a3a0be into atom:master Oct 5, 2017
@leroix leroix deleted the faster-rendering branch October 5, 2017 19:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants