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

Suggestions Rendering Performance #839

Closed
as-cii opened this issue Apr 19, 2017 · 5 comments
Closed

Suggestions Rendering Performance #839

as-cii opened this issue Apr 19, 2017 · 5 comments

Comments

@as-cii
Copy link
Contributor

as-cii commented Apr 19, 2017

Typing a character in Atom involves three main operations: keeping the model up to date, rendering the newly inserted character, and showing suggestions for the current word. These tasks are summarized by the following CPU profile (captured on a real-world JavaScript file with ~ 3000 lines):

screen shot 2017-04-19 at 15 10 57

In this example autocomplete-plus blocked the main thread for 34.7ms and occupied 68% of the entire profile. It's worth noting that during that amount of time, Atom could have rendered two more animation frames.

There are two main reasons why this code path took so long:

  1. Fetching suggestions is unnecessarily complex and slow. Instead of storing and indexing symbols along with their tokens when the buffer changes, we could simply search for all the occurrences of a certain pattern and then query those locations to get the syntax information. The search can be done in C++, which should scale quite nicely as the file gets bigger. A second step here could be to investigate some indexing data structures (such as suffix trees/arrays) to speed this up even further.
  2. Rendering suggestions uses obsolete techniques and displays too many items. The current manual DOM manipulation should be replaced with an etch component that takes care of efficiently rendering an infinite scrolling list, swapping elements in and out as the user scrolls.

/cc: @atom/maintainers

@nathansobo
Copy link
Contributor

Nice summary. Excellent graphical treatment on the profile.

@benogle
Copy link
Contributor

benogle commented Apr 19, 2017

Lol. Apologies. Excited for faster autocomplete. 👍

@leroix
Copy link
Contributor

leroix commented Nov 15, 2017

Just wanted to drop an update here. We've moved subsequence searching into a native function that searches in a background thread. We've also made a bunch of rendering optimizations, so the amount of rendering we do on each key stroke is fairly minimal.

#911
#904
#900
atom/atom#15954
atom/atom#15894

@nathansobo
Copy link
Contributor

Are we good enough to close this out?

@leroix
Copy link
Contributor

leroix commented Nov 16, 2017

There's still some stuff in https://github.com/atom/autocomplete-plus/blob/master/lib/provider-config.js that I want to try to further optimize, but I think we're in pretty good shape here as it stands.

Also notable performance PRs:
atom/superstring#44
atom/superstring#45

@leroix leroix closed this as completed Nov 16, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants