Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Load large files in background - #7060

Closed
nathansobo wants to merge 16 commits into
masterfrom
ns-async-load
Closed

nathansobo wants to merge 16 commits into
masterfrom
ns-async-load

Conversation

@nathansobo

Copy link
Copy Markdown
Contributor

🚨 Work In Progress 🚨

Loading a 3.7MB file created by concatenating jQuery to itself multiple times:

async-load

Constructing the initial set of TokenizedLines hangs the UI thread for large files. This PR performs this work in a background task for files above a certain size to avoid the pause, indicating progress with a progress bar. To integrate smoothly with existing packages, we open a TextEditorLoader item to display progress until the editor is fully loaded, then replace it with the editor afterward. This ensures that no packages attempt to interact with an editor in a partially loaded state.

Remaining Issues

Can't change grammars

We currently use tokenized lines to store horizontal spatial information such as hard tabs, paired unicode characters, soft-wrap indents, etc. This is in addition to their primary purpose of representing syntactic scopes. This entanglement makes it awkward to change the grammar once the file is loaded, because doing so replaces all the tokenized lines with the same placeholder lines we're constructing in the background to clear all the styling, then starts tokenizing again from the beginning. However, this takes a lot of time for a large file. Once the editor is loaded, I don't want to put it back in "background loading" mode because that implies a lot of complexity. Ideally I'd like to store the horizontal spatial information outside of the tokenized lines, so styling could be cleared without throwing away all this computation.

Can't change tab length, invisibles, etc

Again, these require recomputing the tokenized lines from scratch. Invisibles can be dealt with by separating them out into a second rendering phase once our position calculation is more decoupled from the content of the model. Tab lengths are not so easy. We may be able to use our existing metadata about tab locations to update the lengths more efficiently in a synchronous way (without having to scan every token). Or we may want to just disable the ability to change it over a certain size. Or we may need to bite the bullet and figure out how to put the editor back in "background loading" mode after all. I'd like to put that off though.

Long pauses before / after progress bar

The initial pause is due to loading the entire buffer in the background task before beginning processing. I just did this as a first pass implementation and will fix it before merging this. The second pause is autocomplete-plus populating its symbol table. We may want to disable it for now for files above a certain size, then work on optimizing this.

Tasks

  • Display progress bar for loading in background
  • Disallow operations that require recomputation of tokenized lines
  • Optimize background task by computing results in a streaming fashion
  • Do something about autocomplete plus

I may want to push tokenization to a background task in a different PR. That would allow us to at least select an initial grammar for large files instead of the null grammar as is currently the case on this PR. But I think loading huge files without highlighting is enough of an improvement to do that in a second pass.

@Zireael07

Copy link
Copy Markdown

Woo!

Comment thread src/text-editor-loader-element.coffee Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason to not use the <progress> element from the style guide?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only that I didn't know it existed. Will update.

Nathan Sobo added 15 commits June 3, 2015 00:33
Rather than recomputing it for each line. Also, recycle the same
openScopes array for each placeholder since they are immutable and all
the same.
When passed largeFileMode: true, the TokenizedBuffer spawns a background
task to build the initial set of tokenized lines, so that expensive
computation related to scanning for leading whitespace, hard tabs,
paired characters, etc is performed in the background.

This means the TokenizedBuffer won’t be ready to use synchronously
after construction, and we’ll need to handle this in the DisplayBuffer,
TextEditor, and the view as well.
This object serves as a placeholder pane item for editors that are
being loaded asynchronously. It replaces itself with the editor once it
loads, and I will add a progress bar shortly.
Indicate this by change load progress from 1 to 0 again.

Signed-off-by: Max Brunsfeld <[email protected]>
Since progress can drop back to 0, this seems more clean and symmetrical
than adding `onDidStartReloading` or some similar method.

Signed-off-by: Max Brunsfeld <[email protected]>
@nathansobo

Copy link
Copy Markdown
Contributor Author

Rather than doing work in the background, I've found a way to drop a couple features and just not do the work at all.

@nathansobo nathansobo closed this Jun 5, 2015
@Zireael07

Copy link
Copy Markdown

Uh, I'm sure more than a few people are having large files that should be highlighted for grammar, maybe consider getting this merged?

@nathansobo

Copy link
Copy Markdown
Contributor Author

I'm going to look into background highlighting next week, but that's a different story. We won't support folds and soft wraps for a while though which is the only reason we'd really need to do this.

@kevinsawicki
kevinsawicki deleted the ns-async-load branch June 8, 2015 19:00
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.

4 participants