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

Conversation

maxbrunsfeld
Copy link
Contributor

@maxbrunsfeld maxbrunsfeld commented Nov 13, 2017

Fixes atom/atom#16153
Fixes atom/atom#16159
Fixes atom/language-shellscript#88

Background

After enabling the new Subsequence autocomplete provider by default in Atom, we observed a bad slow-down when holding down an alphanumeric key. This was happening because we would were calling findWordsWithSubsequence many times in rapid succession, interspersed with buffer changes. This was resulting in a large number of text buffer layers being created.

Solution

We have made three changes to fix this problem:

  1. When mutating a TextBuffer, we now cancel any findWordsWithSubsequence jobs that were initiated before the mutation and are still queued. Those calls will then resolve with null. This is ok because the result of those calls is no longer needed - a character has been typed since they were performed.

  2. We have optimized the internal TextBuffer::clip_position method so that in its cost now scales linearly with number of buffer layers. Previously it accidentally scaled exponentially with the number of layers because each layer would call clip_position twice on its underlying layer.

  3. We have placed a hard limit on the number of subsequence match variants that we consider when scoring a given match. This stops the findWordsWithSubsequence background thread from using an amount of time and memory that scales exponentially with the length of the query (the word fragment preceding the cursor in Atom).
    I have some ideas for algorithmic improvements to the scoring algorithm that will remove the exponential behavior entirely, but I think we can merge this PR as-is in order to fix the pressing problem in Atom.

@maxbrunsfeld maxbrunsfeld force-pushed the mb-jr-fix-subsequence-slowness branch from f3601f6 to 1623f38 Compare November 13, 2017 21:31
@Arcanemagus
Copy link

Arcanemagus commented Nov 13, 2017

Does this also fix atom/language-shellscript#88? The Atom issues were marked as a duplicate of it, but the behavior is different.

));
);

text_buffer_wrapper->outstanding_workers.insert(worker);
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is the only case where we have outstanding workers, but might it make sense to give this set and the cancellation method a specific name... to cancel outstanding subsequence searches?

Copy link
Contributor Author

@maxbrunsfeld maxbrunsfeld Nov 13, 2017

Choose a reason for hiding this comment

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

I think that in the future, it needs to include other types of workers as well. For example, you can trigger the same problem by calling findAll(regex) many times rapidly, interspersed with buffer changes. We haven't made those calls cancellable yet. I'm not sure if we should do that as part of this PR, since currently there's nothing in Atom that would call that API on every keystroke. Maybe we should just go ahead and do it though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that makes sense. This set is for anything that should be cancelled on the next edit.

Signed-off-by: Justin Ratner <leroix08@gmail.com>
Signed-off-by: Justin Ratner <leroix08@gmail.com>
@maxbrunsfeld maxbrunsfeld force-pushed the mb-jr-fix-subsequence-slowness branch from 9874391 to a6ab5d5 Compare November 14, 2017 01:25
@maxbrunsfeld
Copy link
Contributor Author

maxbrunsfeld commented Nov 14, 2017

Does this also fix atom/language-shellscript#88?

Yes, I believe so! Added to the description. Thanks @Arcanemagus.

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.

Atom crashes when I press and hold a letter key Some text input causing system crash Exponential loop in parsing?
3 participants